variable update

Bruno Desthuilliers onurb at xiludom.gro
Tue Sep 12 11:19:03 EDT 2006


Fredrik Lundh wrote:
(snip)
> 
>    variable = None
> 
>    ... lots of code that may assign to variable ...
> 
>    if variable is not None:
>        print "not defined"

Shouldn't that be:
     if variable is None:
         print "not defined"

?-)

Note to the OP: if None is a valid value for the variable, you may use
another object, ie:

def somefunc(*args, **kw):
  variable = _marker = object()

  (...)

  if variable is _marker:
         print "not defined"

  (...)

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list