Nested function scope problem
Bruno Desthuilliers
onurb at xiludom.gro
Thu Jul 27 12:44:29 EDT 2006
Gerhard Fiedler wrote:
> On 2006-07-27 09:42:16, Bruno Desthuilliers wrote:
>
>
>>>Are you saying Python variables don't hold references to "actual" Python
>>>objects?
>>
>>Exactly.
>>
>>
>>>That idea has been working well for me so far.
>>
>>It can only take you so far. Now it's time you know the truth: there are
>>*no* 'variables' in Python (hence the term 'binding').
>>
>>What you really have is (somewhat simplified, of course) a dict with
>>names as keys and objects references (think of 'smart' pointers) as
>>values. So the name doesn't 'hold' anything - it's really nothing more
>>than a name. And the object doesn't know nothing about which names it's
>>bound to.
>
>
> I see that, and this thread and your and others explanations have been
> helpful in seeing deeper.
>
> But can't this be expressed -- maybe -- as the variable name "holding" the
> reference
s/the/a/
> that is associated to it through the dict? Aside the explicit
> mentioning of the dict (which I agree is in itself a value, especially
> since that dict exists and can be accessed as dict), the image seems to
> provide the same analogy.
What bother me with the "hold" term is that I understand it as meaning
that the name is some kind of container by itself - which it is not.
Consider the following:
d = dict()
d['name'] = 'parrot'
Would you say that the string "name" 'holds a reference' to the string
"parrot" ? Obviously not - it's the dict that holds this reference.
My 2 cents...
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"
More information about the Python-list
mailing list