How to create functors?

Robert Dailey rcdailey at gmail.com
Tue Aug 18 23:03:51 CEST 2009


On Aug 18, 4:01 pm, "Jan Kaliszewski" <z... at chopin.edu.pl> wrote:
> Dnia 18-08-2009 o 22:42:59 Robert Dailey <rcdai... at gmail.com> napisał(a):
>
> > I see what you're saying now. However, why am I able to use print as a
> > function in general-purpose code in my Python 2.6 script, like so:
>
> > def SomeFunction():
> >    print( "Hello World" )
>
> > But, I am not able to do this:
>
> > SomeFunction = lambda: print( "Hello World" )
>
> > ??????
>
> Because (unless you do 'from __future__ import print_function' in Py2.6)
> it's statement, not a functions. In Python you can put any expression
> in parentheses -- it's useful for wraping long lines but changes nothing
> semantically (unless you add a comma -- then you create a tuple, even
> without parentheses, but it'a another story...).
>
> *j
>
> --
> Jan Kaliszewski (zuo) <z... at chopin.edu.pl>

Ah, I see now. I completely fooled myself. This whole time I thought
Python 2.6 was updated to work with both forms of print by default as
a convenience, but still maintain the backwards compatibility.

I understand the situation now. Thanks to everyone for the help.



More information about the Python-list mailing list