Python vs. Lisp: scope issues

anton muhin antonmuhin.REMOVE.ME.FOR.REAL.MAIL at rambler.ru
Tue Oct 14 12:30:39 EDT 2003


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

a1 = accumulator()
print a1(1)
print a1(2)

a2 = accumulator()
print a2(10)
print a2(20)

regards,
anton.





More information about the Python-list mailing list