Namespace Problem with global declaration in module
gmcm at hypernet.com
Wed Apr 26 15:48:25 EDT 2000
spex66 at my-deja.com wrote:
> 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 *
There's your problem. "from test import *" copies names from
test to your namespace. Now dd is another name for None.
yy() affects the dd in test's namespace, not yours.
> >>> yy = zz()
> >>> dd.name
More information about the Python-list