Global Objects...

K

KraftDiner

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?
 
E

Erik Max Francis

KraftDiner said:
myGlobalDictionary doesn't seem to be visible to my someClass methods.
Why? What should I do?

Specify more clearly what is happening, what you wanted it to do, and
why you think it's wrong? You haven't given enough information.
 
C

Chaz Ginger

KraftDiner said:
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?
Is it an oversight that you forgot the ':' on the getValue definition?
You also forgot to do the return. I say the code should look like:

def getValue(self,v) :
return myGlobalDictionary[v]

I am also confused as to what getVal() does.

Chaz
 
D

Dan

KraftDiner said:
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:
.... 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)
....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top