[Zope] testing for "REQUEST is not None"

Willem Broekema willem@pastelhorn.com
Thu, 07 Nov 2002 10:25:01 -0100


Geir B=E6kholt wrote:

> if the method was called directly from somewhere , not through the
> web..
>
> - so that , if you for instance are adding objects programmatically,
> will not be redirected to manage_main...

Also then, the absense of REQUEST can be tested with just 'if REQUEST'?!


Obviously I'm still not making clear what I want to know:

  - 'None' compares to a boolean false

  - 'def something(self, REQUEST=3DNone):' 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
    'if REQUEST is not None:' is equivalent to 'if REQUEST:'

As 'if REQUEST' is shorter than '.. is not None', why not use it instead?

Like this:

   def something(self, REQUEST=3DNone):
     # do actions
     if REQUEST:
       # redirect to ...


It's equivalent to testing for an empty string: why test for the empty=20
string like this:
   if s !=3D ''

when you know s is a string, so you can just do:
   if s:


- Willem