title: Import by filenames passed as arguments
body: <p>I am developing a Python package which does work by taking in user-defined objects all of which are instances of a class which I wrote. The way I have designed is, user passes his/her objects as defined in one or more python scripts (see example below). </p>
  
  <p>I want to access the objects which user defines in the scripts. How can I do that?</p>
  
  <p>I looked at import by filename but to no avail. I even went on to use <code>imp.load_source</code> but didn't solve.</p>
  
  <p>Some typical user-defined objects</p>
  
  <p>Assume for the sake of the problem, all methods are defined in Base. I understand what I am asking for leads to arbitrary code execution, so I am open to suggestions wherein users can pass their instances of the <code>Base</code> class arbitrarily but safely.</p>
  
  <p>foo.py has the following code:</p>
  
  <pre class="lang-py prettyprint-override"><code>from package import Base
  foo = Base('foo')
  foo.AddBar('bar', 'bar')
  foo.AddCow('moo')
  </code></pre>
  
  <p>ooo.py :</p>
  
  <pre class="lang-py prettyprint-override"><code>from package import Base
  ooo = Base('ooo')
  ooo.AddBar('ooo','ooo')
  ooo.AddO(12)
  </code></pre>
  
  <p>And I run my main program as, </p>
  
  <pre class="lang-sh prettyprint-override"><code>main_program -p foo.py ooo.py
  </code></pre>
  
  <p>I want to be able to access <code>foo</code>, <code>ooo</code> in the <code>main_program</code> body.</p>
  
  <h2>Tried:</h2>
  
  <p><strong>I am using python2.7</strong> <em>I know I am using older Python, I will make the move soon</em></p>
  
  <h3><code>importlib</code></h3>
  
  <p>Tried <code>importlib.import_module</code> but it throws <code>ImportError: Import by filename is not supported</code>.</p>
  
  <h3><code>__import__</code></h3>
  
  <p>I tried using <code>__import__('/path/to/file.py')</code> but it throws the same <code>ImportError: Import by filename is not supported.</code></p>
  
  <p>At this point, any solution which lets me use objects defined in user-input scripts works.</p>