Re: Module loading trickery

2010-10-06 Thread Thomas Jollans
On Wednesday 06 October 2010, it occurred to Dave Angel to exclaim: > On 2:59 PM, Thomas Jollans wrote: > > > > % cat a.py > > foo = 'Meh.' > > import b > > > > % cat b.py > > from a import foo > > > > print(foo) > > > > % python a.py > > Meh. > > % > > But there are now two modules containing

Re: Module loading trickery

2010-10-05 Thread Dave Angel
On 2:59 PM, Thomas Jollans wrote: % cat a.py foo = 'Meh.' import b % cat b.py from a import foo print(foo) % python a.py Meh. % But there are now two modules containing separate items foo, one is called __main__, and the other is called a. The former is the script you ran, and the la

Re: Module loading trickery

2010-10-05 Thread Jonas Galvez
Thanks a million, runpy is exactly what I was looking for! I will send you a link to what I'm using it for when it's done. Then you'll understand ;) -- Jonas On Tue, Oct 5, 2010 at 1:06 PM, Thomas Jollans wrote: > On Tuesday 05 October 2010, it occurred to Jonas Galvez to exclaim: > > Is there

Re: Module loading trickery

2010-10-05 Thread Thomas Jollans
On Tuesday 05 October 2010, it occurred to Jonas Galvez to exclaim: > Is there a way to "inject" something into a module right before it's > loaded? > > For instance, a.py defines "foo". b.py print()s "foo". > > I want to load b.py into a.py, but I need to let b.py know about "foo" > before it ca

Re: Module loading trickery

2010-10-05 Thread Jean-Michel Pichavant
Jonas Galvez wrote: Is there a way to "inject" something into a module right before it's loaded? For instance, a.py defines "foo". b.py print()s "foo". I want to load b.py into a.py, but I need to let b.py know about "foo" before it can execute. Is this any way to achieve this? -- Jonas

Module loading trickery

2010-10-05 Thread Jonas Galvez
Is there a way to "inject" something into a module right before it's loaded? For instance, a.py defines "foo". b.py print()s "foo". I want to load b.py into a.py, but I need to let b.py know about "foo" before it can execute. Is this any way to achieve this? -- Jonas -- http://mail.python.org/