
On Jun 30, 2012 9:00 AM, <fiatjaf@yahoo.com.br> wrote:
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 made.
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.
I like it! I've found myself annoyed by writing an if statement using the result of a function call, then realizing "oh wait, I need a reference to that value" and have to go back and rewrite. This would eliminate that and, to my mind, it flows very nicely. +1 from me.