[Zope] Python Scripts

Tom Deprez Tom Deprez" <tom.deprez@uz.kuleuven.ac.be
Mon, 28 May 2001 12:57:20 +0200


euhm, nothing...

if I look back on the script I tried out I had written hassattr ....
Urgh, typos, why do they exist?

Anyway, thanks for the response!

Tom.
----- Original Message -----
From: "Peter Bengtsson" <mail@peterbe.com>
To: "Tom Deprez" <tom.deprez@uz.kuleuven.ac.be>; <zope@zope.org>
Sent: Monday, May 28, 2001 12:15 PM
Subject: Re: [Zope] Python Scripts


> What was wrong with
> if hasattr(context,'coffeebreak'):
>     print "have coffee"
> ?
>
> This is almost the equivalent of DTML's
> <dtml-if coffeebreak>
>
> Assuming your completely skip the REQUEST object out there.
>
> It doesn't have to be 'context' like above or 'self' in External Method.
> You can even do this one any Zope object.
> if has(context.folder['document.html'], 'coffeebreak'):
>   print "had coffee"
>
>
>
> ----- Original Message -----
> From: "Tom Deprez" <tom.deprez@uz.kuleuven.ac.be>
> To: <zope@zope.org>
> Sent: Monday, May 28, 2001 11:38 AM
> Subject: [Zope] Python Scripts
>
>
> > Hi,
> >
> > How can we in the python script check if the a certain variable exists
in
> > the namespace?
> >
> > ie. We can get the value of a variable by using context.myvar or
> > context['myvar'], but both will return an error when the myvar doesn't
> > exists. Now, how can you check if it exists?
> >
> > I tried several things, like context.hasattr('myvar') or
> > context.has_key('myvar') , _hasattr(), _.hasattr() ... etc, but none
seem
> to
> > work. Can somebody tell me if it even is possible? Thanks.
> >
> > Tom.
> >
> >
> > _______________________________________________
> > Zope maillist  -  Zope@zope.org
> > http://lists.zope.org/mailman/listinfo/zope
> > **   No cross posts or HTML encoding!  **
> > (Related lists -
> >  http://lists.zope.org/mailman/listinfo/zope-announce
> >  http://lists.zope.org/mailman/listinfo/zope-dev )
>