How to create functors?

Grant Edwards invalid at invalid
Tue Aug 18 16:55:19 EDT 2009


On 2009-08-18, Robert Dailey <rcdailey at gmail.com> wrote:
> Hello,
>
> I want to simply wrap a function up into an object so it can be called
> with no parameters. The parameters that it would otherwise have taken
> are already filled in. Like so:
>
>
>       print1 = lambda: print( "Foobar" )
>       print1()
>
> However, the above code fails with:
>
>   File "C:\IT\work\distro_test\distribute_radix.py", line 286
>     print1 = lambda: print( "Foobar" )
>                          ^
> SyntaxError: invalid syntax
>
> How can I get this working?

Doesn't this do what you want?

    def print1():
        return print(" Foobar" )

-- 
Grant Edwards                   grante             Yow! I want my nose in
                                  at               lights!
                               visi.com            



More information about the Python-list mailing list