. Python 2.1 function attributes
Barry A. Warsaw
barry at digicool.com
Sat Jan 27 11:23:05 EST 2001
>>>>> "RB" == Robin Becker <robin at jessikat.fsnet.co.uk> writes:
>> Barry also added code to Python 2.1 to let you write, e.g., def
>> f() >> x: x = 1 y = 2 as a short way to spell "whatever the
>> value of x is at the end of the function, return that". I'm
>> sure you'll agree that's much cleaner than the clumsy def f():
>> x = 1 y = 2 return x people suffer with today.
| ....
| mmmhhhh :( what happens with
| def f() >> x:
| return 1
RB> def f() >> x:
| y=2
| return y
RB> seems to me that having multiple ways of doing return is a bad
RB> idea
It was a joke. Tim meant to write "def f() << x" because "the
function f `gets' the value of x". The patch also places the return
value as a function attribute so you really write it like this:
def f() << x:
x = 1
y = 2
print f.x
That both calls f and returns the x attribute value. Add in
__setattr__ semantics and arguments as list comprehensions, and you
get the power and clarity of:
>>> def f(x * [x-1 for x > 1]) << x: pass
...
>>> print f.x = 5
120
What could be more natural than that? <wink, wink, nudge, nudge>
to-be-checked-in-just-after-fred's-optional-braces-patch-ly y'rs,
-Barry
More information about the Python-list
mailing list