[Python-ideas] Combining test and assignment

Steven D'Aprano steve at pearwood.info
Sun Jan 22 02:15:42 CET 2012


Jakob Bowyer wrote:
> Say I have a function that is
> def test():
>     return sometimes_false
> 
> if test() as x:
>     print "Its not false"
> # what happens to x now? is it a NameError or is it None

Neither. It should be syntactic sugar for this:

x = test()
if x:
     print "Its not false"

So x will always be sometimes_false, whatever that happens to be.



-- 
Steven



More information about the Python-ideas mailing list