[ Willem Broekema]
Also then, the absense of REQUEST can be tested with just 'if REQUEST'?!
Yes, but that statement may be misleading. You have a parameter called REQUEST that may or may not be passing to the function. If that parameter were to be omitted, the function would still construct a local variable called "REQUEST", and set it to refer to the None object. You will be testing this local variable, which is certain to exist because of the Python defaulting mechanism (REQUEST=None). On the other hand, if you tried to use the test on a variable that had never been constructed, then Python would throw an exception since it could not be able to find that name.
Obviously I'm still not making clear what I want to know:
- 'None' compares to a boolean false
- 'def something(self, REQUEST=None):' gives REQUEST the value None, if it is omitted
- inside the function, REQUEST is either a Request instance (boolean true) or 'None' (boolean false), so testing for
REQUEST is whatever type was passed in, not a boolean true or false. It behaves like a boolean only for the purposes of the logical test.
'if REQUEST is not None:' is equivalent to 'if REQUEST:'
Not quite, as I explained. The first form tests whether REQUEST is the same as the None object. The second form tests whether REQUEST evaluates to true or false when teste - false will be evaluated for 0, "", {}, and {} as well as for None. BTW, Javascript actis much the same way. For example, "undefined" evaluates to false in a logical test. Cheers, Tom P
As 'if REQUEST' is shorter than '.. is not None', why not use it instead?
Like this:
def something(self, REQUEST=None): # do actions if REQUEST: # redirect to ...
It's equivalent to testing for an empty string: why test for the empty string like this: if s != ''
when you know s is a string, so you can just do: if s:
- Willem
_______________________________________________ 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 )