[Zope] Python Scripts

Peter Bengtsson mail@peterbe.com
Mon, 28 May 2001 12:15:20 +0200


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 )