Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Global Objects...

Reply
Thread Tools

Global Objects...

 
 
KraftDiner
Guest
Posts: n/a
 
      08-16-2006
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?

 
Reply With Quote
 
 
 
 
Erik Max Francis
Guest
Posts: n/a
 
      08-16-2006
KraftDiner wrote:

> 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.

--
Erik Max Francis && http://www.velocityreviews.com/forums/(E-Mail Removed) && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
Freedom is never voluntarily given by the oppressor.
-- Dr. Martin Luther King, Jr.
 
Reply With Quote
 
 
 
 
Chaz Ginger
Guest
Posts: n/a
 
      08-16-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?
>

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
 
Reply With Quote
 
Dan
Guest
Posts: n/a
 
      08-17-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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FWSM/PIX and Dynamic PAT using global IP range vs. global interface vs. global IP Hoffa Cisco 1 10-25-2006 06:50 PM
FWSM/PIX and Dynamic PAT using global IP range vs. global interface vs. global IP Hoffa Cisco 0 10-25-2006 01:04 PM
Could not load type 'Global.yaddayadda'. - Global.asax.cs Daniel Bass ASP .Net 2 12-31-2003 03:57 PM
Global variables on par with ASP's global.asa Wayne ASP .Net 2 11-11-2003 10:58 PM
Global Error handling in Applicatio_Error() of Global.asax VSK ASP .Net 1 07-29-2003 03:12 AM



Advertisments