title: Python module as global instance of class
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2447353/getattr-on-a-module"><strong>getattr</strong> on a module</a>  </p>
  </blockquote>
  
  
  
  <p>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:</p>
  
  <pre><code>class Manager:
  
      def func(self):
          print('stuff')
  
  instance = Manager()
  
  def func():
      instance.func()
  </code></pre>
  
  <p>Is there a way to make module.x returns module.instance.x? (kind of like a module level property)</p>
  
  <p>UPDATE:  The answer in <a href="https://stackoverflow.com/questions/2447353/getattr-on-a-module">this question</a> 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:</p>
  
  <pre><code>class Manager:
  
      def __init__(self):
          self.x = 3
  
      def func(self):
          print('stuff')
  
  sys.modules[__name__] = Manager()
  
  &gt;&gt;&gt; module.func
  &lt;func&gt;
  &gt;&gt;&gt; module.x
  3
  &gt;&gt;&gt; module.Manager
  AttributeError
  </code></pre>