Feature suggestion -- return if true

Grant Edwards invalid at invalid.invalid
Tue Apr 12 15:50:23 CEST 2011


On 2011-04-12, James Mills <prologic at shortcircuit.net.au> wrote:
> On Tue, Apr 12, 2011 at 4:08 PM, Nobody <nobody at nowhere.com> wrote:
>> It should be abundantly clear that this only returns if the expression is
>> considered true, otherwise it continues on to the following statements.
>
> Uggh come on guys. We've been over this.
> You cannot make that assumption.

You most certain can.  Try it yourself in an interpreter.  The
OP's code snippit will not return if expr is false, rather it will
continue executing in the current context:

>>> def foo(expr):
...   __temp__ = expr                         # these two lines are
...   if __temp__:  return __temp__           # the OP's code snippet
...   print "the code snippet did not return"
... 
>>> print foo(9)
9
>>> 
>>> print foo(0)
the code snippet did not return
None
>>> 

-- 
Grant Edwards               grant.b.edwards        Yow! One FISHWICH coming
                                  at               up!!
                              gmail.com            



More information about the Python-list mailing list