static class variables and module scope

Discussion in 'Python' started by The Dark Seraph, Jul 19, 2004.

  1. I have a singleton object that works perfectly from inside my main .py
    file. However, when I want to access the object that backs the
    singleton from another file ( either from an execfile() or thru my
    telnet listener ), it appears the underlying object is reset to null,
    resulting in a duplicate object being created.

    I figure I am doing something painfully stupid, but for the life of me,
    I can't see it.

    Here is my singleton wrapper:

    class SingletonWrapper:
    __instance = None
    def __init__ ( self, user = None, password = None ):
    if SingletonWrapper.__instance is None:
    SingletonWrapper.__instance = ImplSingletonWrapper ( user, password )
    def instance ( self ):
    return SingletonWrapper.__instance

    In my ImplSingletonWrapper class, I print out that I am creating a new
    object when its constructor is called. Inside the owner file, it is
    only called once , but if I do SingletonWrapper().instance() from
    anohter module, it makes a new object, and id() reports different ids.

    I banged my head against this yesterday, and today doesn't seem to be
    going any better, any ideas out there?

    --
    | Fight Censorship, Boycott Wal-Mart
    Now is the winter of your discontent! - Stewie
    The Dark Seraph, Jul 19, 2004
    #1
    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. Paul Opal
    Replies:
    12
    Views:
    931
    Paul Opal
    Oct 11, 2004
  2. SaravanaKumar
    Replies:
    6
    Views:
    9,365
    Tony Morris
    Oct 19, 2004
  3. Steven T. Hatton
    Replies:
    9
    Views:
    459
  4. Christoph

    Scope of static class variables

    Christoph, Apr 3, 2007, in forum: Java
    Replies:
    16
    Views:
    586
    Chris Uppal
    Apr 5, 2007
  5. Hicham Mouline
    Replies:
    5
    Views:
    2,347
    James Kanze
    Dec 19, 2008
Loading...

Share This Page