Thanks a million, runpy is exactly what I was looking for!<div><br></div><div>I will send you a link to what I'm using it for when it's done. Then you'll understand ;) </div><div><br></div><div>-- Jonas<br><br>
<div class="gmail_quote">On Tue, Oct 5, 2010 at 1:06 PM, Thomas Jollans <span dir="ltr"><<a href="mailto:thomas@jollybox.de">thomas@jollybox.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
On Tuesday 05 October 2010, it occurred to Jonas Galvez to exclaim:<br>
<div><div></div><div class="h5">> Is there a way to "inject" something into a module right before it's<br>
> loaded?<br>
><br>
> For instance, a.py defines "foo". b.py print()s "foo".<br>
><br>
> I want to load b.py into a.py, but I need to let b.py know about "foo"<br>
> before it can execute.<br>
><br>
> Is this any way to achieve this?<br>
<br>
</div></div>No. That's just not how Python works. [*]<br>
However, you can simply import foo from a explicitly within b. Though you<br>
might want to rethink what you're doing. Maybe.<br>
<br>
% cat a.py<br>
foo = 'Meh.'<br>
import b<br>
<br>
% cat b.py<br>
from a import foo<br>
<br>
print(foo)<br>
<br>
% python a.py<br>
Meh.<br>
%<br>
<br>
<br>
 - Thomas<br>
<br>
[*] Actually, it is possible with runpy. But don't. Really, don't, unless you<br>
have a very good reason to do so, and judging by the way the question was<br>
asked, I don't think you do.<br>
<font color="#888888">--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br></div>