python3: 'where' keyword

Bengt Richter bokr at oz.net
Sat Jan 8 06:31:08 EST 2005


On Sat, 08 Jan 2005 16:42:16 +1000, Nick Coghlan <ncoghlan at iinet.net.au> wrote:

>Nick Coghlan 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:
>
>class C(object):
>
>   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?

   x = term1 + term2 where:
       term1 = a*b where:
           a = 123
           b = 456
       term2 = math.pi

Reminds me of some kind of weird let ;-)

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 ;-)

Regards,
Bengt Richter



More information about the Python-list mailing list