python gripes survey

Ryan Lowe ryanlowe0 at msn.com
Thu Aug 28 18:43:20 EDT 2003


 [smarter_than_you]
>How about this for a symmetrical, Pythonesque syntax:
>
>def sumdif(a, b):
 > sum = a + b
 > dif = a - b
 > return sum, dif
>
>#normal syntax:
>s, d = sumdif(5,7)
>
>#additional syntax with named returns:
>
>(s=sum, d=dif)=sumdif(5, 7)
>
>#eqivalent to:
>
>(d=dif, s=sum)=sumdif(5, 7)
>
>#I call it 'symmetrical' because we can do this:
>
>(s=sum, d=dif)=sumdif(a=5, b=7)
>
>Not sure how easy to implement this would be, or how it affects the
>scope of locals and such, but it looks nice on paper.


not bad. heres an alternative:

s, d = (sum, dif) from sumdif(5, 7)
d, s = (dif, sum) from sumdif(5, 7)

uses the from keyword. makes it look like a parallel assignment.







More information about the Python-list mailing list