Global Objects...

Discussion in 'Python' started by KraftDiner, Aug 16, 2006.

  1. KraftDiner

    KraftDiner Guest

    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?
    KraftDiner, Aug 16, 2006
    #1
    1. Advertising

  2. 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.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.
    Erik Max Francis, Aug 16, 2006
    #2
    1. Advertising

  3. KraftDiner

    Chaz Ginger Guest

    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
    Chaz Ginger, Aug 16, 2006
    #3
  4. KraftDiner

    Dan Guest

    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
    Dan, Aug 17, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VSK
    Replies:
    1
    Views:
    754
    Alvin Bruney
    Jul 29, 2003
  2. Wayne
    Replies:
    2
    Views:
    452
    Wayne
    Nov 11, 2003
  3. Daniel Bass
    Replies:
    2
    Views:
    6,846
    Daniel Bass
    Dec 31, 2003
  4. 2obvious

    no global constants in global.asax?

    2obvious, Sep 4, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,786
  5. 7stud
    Replies:
    11
    Views:
    661
    Dennis Lee Bieber
    Mar 20, 2007
Loading...

Share This Page