Default method arguments

Gregory Petrosyan gregory.petrosyan at gmail.com
Tue Nov 15 15:50:33 EST 2005


I'm not very familiar with Python, so please explain me why should
containers be used?
For example in one of Paul Graham's essays there's an example of
'generator of accumulators' in Python:

def foo(n):
    s = [n]
    def bar(i):
         s[0] += i
         return s[0]
    return bar

1) So, why just using 's = n' is not suitable? (It doesn't work, Python
'doesn't see' s, but why?)
2) Is 'foo.s = n' a correct solution? It seems to be a little more
elegant.  (I tested it, and it worked well)

Sorry for possibly stupid questions.




More information about the Python-list mailing list