title: How to dynamically import module class
body: <p>I have following structure:</p>
  
  <pre><code>app.py
  
  modules
      |
      -- __init__.py
      |
      -- update.py
  </code></pre>
  
  <p>I try to call function from <code>modules/update.py</code> dynamicaly:</p>
  
  <pre><code>import sys
  
  arguments = sys.argv
  module = arguments[1]
  command = arguments[2]
  moduleObj = __import__('modules.'+module)            # returns module object "modules"
  submodule = getattr(moduleObj, module)    # returns the module object "modules.update"
  moduleClass = getattr(submodule, module)  # returns the class object "update"
      # this works because the class has the same name as the file it contains it.
      # if the names are different then you have to change that accordingly 
  result = getattr(moduleClass, command) # returns the attribute with the name =command
  print result()
  </code></pre>
  
  <p>but I catch a error: </p>
  
  <blockquote>
    <p>File "app.py", line 12, in 
        print result() TypeError: unbound method test() must be called with update instance as first argument (got nothing instead)</p>
  </blockquote>
  
  <p>What's wrong? Help me please!</p>
  
  <p>ps: <code>update.py</code> code:</p>
  
  <pre><code>import os
  
  class update:
      def repositories(self):
          os.system('sudo apt-get update')
  
      def system(self):
          os.system('sudo apt-get -y upgrade')
  
      def distributive(self):
          os.system('sudo apt-get -y dist-upgrade')
  
      def all(self):
          self.repositories()
          self.system()
          self.distributive()
  
      def test(self):
          print 'test complete!'
  </code></pre>