title: Dynamically import a method in a file, from a string
body: <p>I have a string, say: <code>abc.def.ghi.jkl.myfile.mymethod</code>. How do I dynamically import <code>mymethod</code>?</p>
  
  <p>Here is how I went about it:</p>
  
  <pre><code>def get_method_from_file(full_path):
      if len(full_path) == 1:
          return map(__import__,[full_path[0]])[0]
      return getattr(get_method_from_file(full_path[:-1]),full_path[-1])
  
  
  if __name__=='__main__':
      print get_method_from_file('abc.def.ghi.jkl.myfile.mymethod'.split('.'))
  </code></pre>
  
  <p>I am wondering if the importing individual modules is required at all.</p>
  
  <p>Edit: I am using Python version 2.6.5.</p>