[Zope] testing for "REQUEST is not None"
Jens Vagelpohl
jens@zope.com
Thu, 7 Nov 2002 08:03:29 -0500
saying "if REQUEST is not None" is a much more explicit way of saying=20
"this condition fails because REQUEST really was never passed in".=20
since "None" is the default argument for REQUEST you know for a fact=20
that REQUEST was never passed into the function.
it is probably true that any other "non-truth" value should make the=20
condition fail, but some people might prefer to have it not fail and=20
throw errors instead to find out that somehow garbage got passed in as=20=
the REQUEST argument.
jens
On Thursday, Nov 7, 2002, at 06:25 US/Eastern, Willem Broekema wrote:
> 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=20
> 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=20
> 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
>
>
> _______________________________________________
> 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 )