title: Python dynamic import methods from file
body: <p>I have multiple files with a structure like a file <code>example.py</code>:</p>
  
  <pre><code>    def initialize(context):
          pass
  
  
      def daj_omacku_teplu(context, data):
          pass
  
  
      def hmataj_pomaly(context, data):
          pass
  
  
      def chvatni_paku(context, data):
          pass
  
  
      def mikaj_laktom(context, data):
          pass
  </code></pre>
  
  <p>and I need to be able to dynamically import methods from "example.py" in a different python file like:</p>
  
  <pre><code>    for fn in os.listdir('.'):
         if os.path.isfile(fn):
             from fn import mikaj_laktom
             mikaj_laktom(example_context, sample_data)
  </code></pre>
  
  <p>For multiple reasons, I can not change the structure of <code>example.py</code> so I need to make a mechanism to load methods and evaluate them. I tried to use <code>importlib</code> but it can only import a class, not file with only methods defined.
  Thanks for the help.</p>