Nested function scope problem
Bruno Desthuilliers
onurb at xiludom.gro
Thu Jul 27 11:02:49 EDT 2006
Antoon Pardon wrote:
> On 2006-07-27, Bruno Desthuilliers <onurb at xiludom.gro> wrote:
>
>>danielx wrote:
>>
>>>Bruno Desthuilliers wrote:
>>>
>>
>>(snip)
>>
>>>>>Surprising for me are actually two things: 1- the fact itself, and 2- that
>>>>>term "binding", and that whatever it means > (I'll have to read more on that,
>>>>>now that I know the term)
>>>>
>>>>a "binding" is the association of a name and a reference to an object in
>>>>a given namespace. It's different from the common notion of "variable",
>>>>which is usually a symbolic name for a memory address storing a value
>>>>(like a pointer to an object's address).
>>>
>>>
>>>Wait, I'm not sure I see the difference. Isn't "reference" ~ "C
>>>pointer".
>>
>>For a very large definition of '~' !-)
>>
>>
>>>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').
>
>
> That depends on what you want to mean with the term. IMO 'variables'
> in python behave sufficiently similar as in other languages
Which ones ? C ? or Lisp ? Or Haskell ?
> to use
> the term.
IYO.
>
>>What you really have is (somewhat simplified, of course) a dict with
>>names as keys and objects references (think of 'smart' pointers) as
>>values.
>
>
> That is just an implementation issue. Nothing prevents variables to
> be associated with an index in a list.
Do you understand what "somewhat simplified" means ?
>
>>So the name doesn't 'hold' anything - it's really nothing more
>>than a name.
>
>
> In a language like C the name doesn't hold anything either.
Yes : it holds type and storage class informations too.
> The name is just a way for refering to a memory space which
> will hold something.
The name is a symbolic name for a memory address in which bits will be
stored (and the type information is used to know how to interpret the
bits at this address - I leave storage class problems aside). There's a
direct translation from symbolic name to memory address to bits. Which
is not the case in Python...
>
>>And the object doesn't know nothing about which names it's
>>bound to.
>
>
> In a language like C, the value '3' doesn't know which variables
> will hold it either.
Indeed. Now could you tell us what was your point, exactly ?
--
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