[Python-ideas] the optional "as" statement inside "if" statements

fiatjaf at yahoo.com.br fiatjaf at yahoo.com.br
Sat Jun 30 15:59:54 CEST 2012

the idea is to make an variable assignment at the same time that the
existence of that variable -- which is being returned by a function -- is

suppose we are returning a variable from the method 'get' from the
'request' object and them making some stuff with it, but that stuff we will
only do if it exists, if not, we'll just pass, instead of writing:

variable = self.request.get('variable')
if variable:
   print variable

we could write

if self.request.get('variable') as variable:
   print variable

seems stupid (or not?), but with lots of variables to process, this
pre-assignment could be very unpleasant -- especially if, as the in the
example case, very little use will be made of the tested variable.

also, the "as" expression already exists and is very pythonic.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20120630/fb6455e5/attachment.html>

More information about the Python-ideas mailing list