Global Objects...

Dan bounces at foo.org
Wed Aug 16 20:16:10 EDT 2006


KraftDiner wrote:
> I have a question..
> 
> myGlobalDictionary = dictionary()
> 
> 
> class someClass:
>    def __init__(self):
>       self.x = 0;
>    def getValue(self, v)
>       myGlobalDictionary.getVal(v)
> 
> 
> myGlobalDictionary doesn't seem to be visible to my someClass methods.
> Why?  What should I do?
> 

This works:

 >>> class dictionary(dict):
...     def getVal(self, key):
...         return self[key]
...
 >>> myGlobalDictionary = dictionary()
 >>>
 >>> myGlobalDictionary['spam'] = 'eggs'
 >>>
 >>> class someClass:
...    def __init__(self):
...       self.x = 0;
...    def getValue(self, v):
...       return myGlobalDictionary.getVal(v)
...
 >>>
 >>> mySomeThing = someClass()
 >>>
 >>> print mySomeThing.getValue('spam')
eggs
 >>>


-- 
dedded att verizon dott net



More information about the Python-list mailing list