Namespace Problem with global declaration in module

spex66 at my-deja.com spex66 at my-deja.com
Wed Apr 26 10:54:41 EDT 2000


Hi,
it seemed very simple but don't worked like expected:

#FILE: test.py
dd = None #INIT a shadow instance for automated access
class zz:
    #ONLY one class will be instantiated
    def __init__(self):
        self.name = 'hallo'
        global dd
        dd = self
#END OF FILE

>>> from test import *
>>> yy = zz()
>>> dd.name
    ...
    AttributeError
    ...

++++++++++++++
the same code interactive at the python console works perfect!
>>> ...same as above...
>>> dd.name
    'hallo'

any hints?
in use: 1.5.2 / idle0.5
thanks

Peter
(=PA=)



Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list