Nested scopes: design or implementation?

logistix logstx at bellatlantic.net
Tue Mar 5 21:31:55 EST 2002


Is the following code operating this way by design or is it just
implementation?  It seems to indicate that the nested function is redefined
each time the parent function is called.  Is this necessary or desirable?

Just wondering what other people think.

>>> text = "random text"
>>> def function():
            def attribute( bindNow = text):
                print bindNow
            function.attribute = attribute
...
>>> function.attribute()
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
AttributeError: attribute

>>> function()
>>> function.attribute()
random text

>>> text = "new random Text"
>>> function.attribute()
random text

>>> function()
>>> function.attribute()
new random Text
>>>
--
-






More information about the Python-list mailing list