[mod_python] psp

Julien Cigar jcigar at ulb.ac.be
Mon Jun 12 08:55:57 EDT 2006

Hello list,

I have a little problem with psp (I'm using psp as a template engine)

In one of my templates I have :
<input type="text" class="scientific_name" name="scientific_name" 
value="<%= invasive.scientific_name %>" />

The problem I have is that I'm using this form in different context and 
sometimes the 'invasive' object doesn't exists.
Is there a way to "display-only-if-object-exist" ? What I would like to 
avoid is things like :

    # BEGIN
    <%= invasive.scientific_name %>

I tried something like :

def show_if_defined(s, obj=globals()):
    for part in s.split('.') :
        if not hasattr(obj, part):
            return ''
        obj = getattr(obj, part)
    return obj

<input type="text" class="scientific_name" name="scientific_name" 
value="<%= show_if_defined('invasive.scientific_name') %>" />

but without success ...

Any idea ?


Julien Cigar
Belgian Biodiversity Platform
Université Libre de Bruxelles
Campus de la Plaine CP 257
Bâtiment NO, Bureau 4 N4 115C (Niveau 4)
Boulevard du Triomphe, entrée ULB 2
B-1050 Bruxelles
office: jcigar at ulb.ac.be
home: mage at mordor.ath.cx

More information about the Mod_python mailing list