[Prev][Next][Index][Thread]

Re: Closures



In article <3b770c44@pfaff.ethz.ch>, "Samuele Pedroni" 
<pedroni@inf.ethz.ch> wrote:

> [Eric Kidd]
> >
> > Urgh.  So Python's closures are still broken:
> There is simply another idiomatic way to get the same:
> 
> class counter:
>   def __init__(self):
>      self.n = 0
>   def __call__(self):
>      self.n = self.n + 1
>      return self.n
> 
> c=counter()
> print c()
> print c()

That's not a "closure", it's an "object".  They can be used for many fo 
the same things, but they are different.

-- Bruce



Follow-Ups: References: