Import object from file without running that file's imports
<p>Not sure this is possible, but would like to know if there are any suggestions.</p>

<p>Say I have a file foo.py which looks like</p>

<pre><code>import doesnotexist

bar = "Hello, World!"
</code></pre>

<p>I want to do a <code>from foo import bar</code>, but this will fail due to the import not existing in the scope of this new file.</p>

<p>One way of doing this is putting <code>bar</code> in a new file called <code>bar.py</code> and have <code>foo.py</code> also import that, but would like to skip that if possible.</p>

<p>Any ideas?</p>
