Where do nested functions live?

Steven D'Aprano steve at REMOVE.THIS.cybersource.com.au
Sat Oct 28 03:56:23 EDT 2006


I defined a nested function:

def foo():
    def bar():
        return "bar"
    return "foo " + bar()

which works. Knowing how Python loves namespaces, I thought I could do
this:

>>> foo.bar()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: 'function' object has no attribute 'bar'

but it doesn't work as I expected.


where do nested functions live? How can you access them, for example, to
read their doc strings?



-- 
Steven.




More information about the Python-list mailing list