how to write function that returns function

Fernando Pérez fperez528 at yahoo.com
Fri May 17 18:33:23 EDT 2002


Paul Graham wrote:

> but it is considered ugly, and the canonical way to
> do this seems to be by defining a class:
> 
> class foo:
>   def __init__(self, n):
>       self.n = n
> 
>   def __call__(self, i):
>       self.n += i
>       return self.n
                   ^^^
I think you mean:

       return self


Cheers,

f.



More information about the Python-list mailing list