title: How to use a variable in a module from the script that called the module
body: <p>I would like to make a plugin system for my script.</p>
  
  <p><strong>How plugins are loaded</strong></p>
  
  <p>The plugins are python modules stored in a specified folder.</p>
  
  <p>I import the modules with this code:</p>
  
  <pre><code>class Igor:
  
      # ...
  
      def load_plugins(self):
  
          for file in os.listdir(self.plugins_folder):
  
              try:
                  __import__(file)
              except Exception as error:
                  sys.exit(error)
  
      # ...
  </code></pre>
  
  <p><strong>The variable I want to make available in the plugins</strong></p>
  
  <p>I have a variable named <code>igor</code> who is an instance of <code>Igor</code>:</p>
  
  <pre><code>if __name__ == "__main__":
  
      # ...
  
      igor = Igor()
  
      # ...
  </code></pre>
  
  <p><strong>What I want the plugins developers able to do</strong></p>
  
  <p>I want to make plugins development easy and <code>igor</code> have all the methods needed to make it easy.</p>
  
  <p>At best it should be something like this (in <code>__init__.py</code>):</p>
  
  <pre><code>from plugins.files.files import Files
  
  igor.register_plugin("files", Files())
  </code></pre>
  
  <p><strong>How can I do that?</strong></p>
  
  <p>I really don't see how to do this <code>globals()</code> display <code>igor</code> in my main script but there is nothing in the globals from the menu (as expected from a module, it is sandboxed I supposed).</p>
  
  <p>Any ideas?</p>