python3: 'where' keyword
elephantum at dezcom.mephi.ru
Sat Jan 8 12:43:36 CET 2005
Bengt Richter wrote:
>>>It also allows the necessary but uninteresting setup for an expression
>>>to be moved "out of the way", bringing the expression that does the real
>>>work to prominence.
>>Killer app for this keyword:
>> x = property(get, set) where:
>> def get(self):
>> return "Silly property"
>> def set(self, val):
>> self.x = "Told you it was silly"
> Yes, that is cool and it _is_ an interesting idea. Are suites nestable? E.g., is this legal?
> And, is the whole thing after the '=' an expression? E.g.,
> x = ( foo(x) where:
> x = math.pi/4.0
> ) where:
> def foo(x): print 'just for illustration', x
> or is this legal?
> for y in ([foo(x) for x in bar] where:
> bar = xrange(5)
> ): baz(y) where:
> def baz(arg): return arg*2
> Not trying to sabotage the idea, really, just looking for clarification ;-)
yes, all your examples are correct. And that's the way I'd like to use
More information about the Python-list