Tian a écrit :
I want to create a object directory called Context in my program, which
is based on a dict to save and retrieve values/objects by string-type
name. I have the definition like this:

utils.py
--------------------
global sysctx

class Context:
    def __init__(self):
    def set(self, name, obj, overwrite=True):
    def get(self, name):
    def has(self, name):

def init():
    global sysctx
    sysctx = Context()

def getContext():
    global sysctx
    return sysctx

Why using a (not so) global variable here ? If your problem is to make sure you have only one instance of Context in your program, there are cleaner solutions - one of them being a Singleton (you'll find all needed doc and exemples on the net - google is your friend !-).



-- http://mail.python.org/mailman/listinfo/python-list

Reply via email to