Possible Duplicate:
getattr on a module
I have a module which defines a Manager class in it. I would like the module to create an instance of this class and have the module serve as a "global instance" of this class. For example:
class Manager:
def func(self):
print('stuff')
instance = Manager()
def func():
instance.func()
Is there a way to make module.x returns module.instance.x? (kind of like a module level property)
UPDATE: The answer in this question covers only half of my use case (i.e., it is NOT a duplicate, what that question is asking is different); I also need the module's attribute to also be available. Example:
class Manager:
def __init__(self):
self.x = 3
def func(self):
print('stuff')
sys.modules[__name__] = Manager()
>>> module.func
<func>
>>> module.x
3
>>> module.Manager
AttributeError