Whre is my object ??

King Kuta mr.kuta at libero.it
Tue Jun 3 23:42:57 CEST 2003


Ok, a little riddle for he Python community.

Follow this code (interactive):

>>> class marco:
...     pass
...
>>> objlist[0]=marco
>>> del marco
>>> objlist[0]
<class __builtin__.marco at 0x023824D8>
>>> objlist[0].me =23
>>> objlist[0].me
23
>>> marco
  File
"C:\PROGRA~1\PYTHON~1.2\Lib\site-packages\wxPython\tools\boa\ExternalLib\Pyt
honInterpreter.py", line 69, in push
    exec code in self.locals
  File "<console>", line 1, in ?
'''exceptions.NameError : name 'marco' is not defined'''
>>>

Evidently "marco" object does not exist in the utermost scope (__builtin__
?)
but it exit "inside" the list object and can be not only referenced but
assignd too.
So where is my object? (apart from the obvious mem location at 0x023824D8)
Does it have a scope in which it exist ?
Do list "create" a scope?
Is it another riddle on identifiers?

Thanks,
marco






More information about the Python-list mailing list