[Zope] Python Scripts

sean.upton@uniontrib.com sean.upton@uniontrib.com
Tue, 29 May 2001 11:47:23 -0700


Why not try a try/except statement, instead of an if/else... unless someone
knows of another way to do this...

Sean

-----Original Message-----
From: Peter Bengtsson [mailto:mail@peterbe.com]
Sent: Monday, May 28, 2001 3:15 AM
To: Tom Deprez; zope@zope.org
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 )


_______________________________________________
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 )