loading program's global variables in ipython
Peter Otten
__peter__ at web.de
Sun Mar 22 15:22:11 EDT 2009
per wrote:
> 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
More information about the Python-list
mailing list