how to write function that returns function

Max Ischenko max at malva.com.uaREMOVE.IT
Tue May 21 04:00:10 EDT 2002


 Paul Graham wrote:

> Thanks to several people who have sent me Python
> "translations" for the following:
> 
> def foo(n):
>  s = [n]
>  def bar(i):
>    s[0] += i
>    return s[0]
>  return bar

> 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

In case anyone interested further in subject check out
http://www.paulgraham.com/icad.html

-- 
panic("kmem_cache_init(): Offsets are wrong - I've been messed with!");
	2.2.16 /usr/src/linux/mm/slab.c



More information about the Python-list mailing list