Python vs. Lisp: scope issues
David Eppstein
eppstein at ics.uci.edu
Tue Oct 14 13:59:50 EDT 2003
In article <bmh8bf$f79$1 at news.peterlink.ru>,
anton muhin <antonmuhin.REMOVE.ME.FOR.REAL.MAIL at rambler.ru> wrote:
> In addition to s[0] hack, I'd like to suggest the following code. Any
> comments are highly appreciated:
>
> class Scope(object):
> pass
>
> def accumulator():
> scope = Scope()
> scope.n = 0
> def f(n):
> scope.n += n
> return scope.n
> return f
Definitely cleaner than the s[0] hack. I'll have to remember that the
next time I need to work around the scope limitation.
--
David Eppstein http://www.ics.uci.edu/~eppstein/
Univ. of California, Irvine, School of Information & Computer Science
More information about the Python-list
mailing list