loading program's global variables in ipython

P

per

hi all,

i have a file that declares some global variables, e.g.

myglobal1 = 'string'
myglobal2 = 5

and then some functions. i run it using ipython as follows:

[1] %run myfile.py

i notice then that myglobal1 and myglobal2 are not imported into
python's interactive namespace. i'd like them too -- how can i do
this?

(note my file does not contain a __name__ == '__main__' clause.)

thanks.
 
P

Peter Otten

per said:
i have a file that declares some global variables, e.g.

myglobal1 = 'string'
myglobal2 = 5

These aren't declarations, this is exectutable code.
and then some functions. i run it using ipython as follows:

[1] %run myfile.py

i notice then that myglobal1 and myglobal2 are not imported into
python's interactive namespace. i'd like them too -- how can i do
this?

(note my file does not contain a __name__ == '__main__' clause.)

thanks.

Use

%run -i myfile.py

or

execfile("myfile.py") # not ipython-specific

Peter
 
R

R. David Murray

per said:
hi all,

i have a file that declares some global variables, e.g.

myglobal1 = 'string'
myglobal2 = 5

and then some functions. i run it using ipython as follows:

[1] %run myfile.py

i notice then that myglobal1 and myglobal2 are not imported into
python's interactive namespace. i'd like them too -- how can i do
this?

(note my file does not contain a __name__ == '__main__' clause.)

I'm not familiar with IPython, but perhaps 'from myfile import *'
would do what you want?
 
E

Esmail

Peter said:
Use

%run -i myfile.py

or

execfile("myfile.py") # not ipython-specific

thanks for these suggestions Peter, I have had exactly the same problem
and was looking for a way around it -- this will be very helpful.

Esmail

ps: for some reason I am unable to post to the
gmane.comp.python.ipython.user group. For one I can't install the
Windows version of iPython (Linux works superfine :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top