Strange Python 2.1 return style (was Re: . Python 2.1 function attributes)

Peter Hansen peter at engcorp.com
Sat Jan 27 10:21:42 EST 2001


Tim Peters wrote:
> 
> > It seems to me even kludgier than print>>.
> 
> 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.

Is there a smiley missing from the above?  Sounds like a 
bad April Fool's joke, to me.

Given what 'print >>' is supposed to do, wouldn't
'def f() >> x' suggest something more along the lines
of "take whatever is returned by f() and stuff output
it to x"?  

So now we have to deal not only with an unnecessary 
addition to the print statement, that looks like
a foreign language (not Python), but now we are
going to have the same operator be used in a 
different context with a completely different 
meaning?  (I agree on one level with those who
objected to 'print >>', although I happen to think
I'll actually use it and appreciate it, but at
least it rides on the C++ connotation of stuffing
data into something, instead of just pointing 
out the thing that data will be pulled out of...)

I think some people are starting to get nervous
about '>>' and other such non-intuitive, C++-like
cryptic sugary syntax.

Whatever happened to 'one way of doing things',
and 'simpler is better than completely twisted'?



More information about the Python-list mailing list