title: Dynamic Import - Python - Call function not working
body: <p>I am having some trouble with dynamically importing Classes and attempting to run functions in said classes. This is my problem, specifically. </p>
  
  <p>I have a python script <code>dyn_imports.py</code> in a director called <code>dynamic_imports</code>. Inside this folder is a subdir called <code>scripts</code>. In this scripts directory there is an <code>__init__.py</code> and a python class called <code>AbhayScript.py</code>. In the class <code>AbhayScript</code>, there is a function called <code>say_hello()</code></p>
  
  <p>My objective is: From <code>dyn_imports.py</code>, I would like to be able to import <code>scripts.AbhayScript</code> and call the function <code>say_hello()</code> in <code>AbhayScript</code></p>
  
  <p>So far, I have attempted a variety of options including <code>__import__</code>, <code>importlib.import_module</code> and <code>pydoc.locate</code>. All of these options give me access to the <code>module</code> AbhayScript but when I try a <code>getattrs()</code> or try to call the object, I get an error stating that its not callable or has no attribute. </p>
  
  <p><strong>dyn_imports.py - One of my experiments</strong></p>
  
  <pre><code>myclass = 'scripts.AbhayScript'
  
  import importlib
  mymod = importlib.import_module(myclass)
  mod,newclass = myclass.rsplit('.',1)
  ncls = getattr(mod,newclass) #throws an AttributeError that 'str' object has no attribute
  </code></pre>
  
  <p><strong>AbhayScript.py code</strong></p>
  
  <pre><code>class AbhayScript(object):
  
      def say_hello(self):
          print 'Hello Abhay Bhargav'
  </code></pre>
  
  <p>The directory structure is as follows</p>
  
  <p><a href="https://i.stack.imgur.com/AhxRe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AhxRe.png" alt="Directory Structure of Project"></a></p>
  
  <p>The <strong>init</strong>.py in the scripts folder is empty. </p>
  
  <p><strong>I have attempted nearly all the solutions in Stackoverflow, but I am a little flummoxed by this one. What am I doing wrong?</strong></p>