[IPython-user] python vs. ipython

Fernando Perez Fernando.Perez at colorado.edu
Tue Oct 25 14:09:50 CDT 2005


Glen W. Mabey wrote:

>>You need to be careful if yourscript imports things which you are also 
>>modifying, due to the nature of python's import statement.  There have been 
>>discussions in the past on this topic.
> 
> 
> Frequently I find myself in precisely this scenario: I'm editing a class
> that is imported by the script that I'm running.  Hence, I have to exit
> ipython in order to get the newer version loaded.  

Well, what I do in that case is put

import foo
reload(foo)  # remove when done testing

statements for the modules I'm modifying.  It's a bit of a hack, but a small 
and simple enough one that I don't mind it.

> For my purposes, it would be very convenient if there were a
> command-line option to specify a script to %run immediately after
> ipython has started.  Something like:
> 
>     ipython -run yourscript.py
> 
> Ideally, as soon as the script finishes, the user would be returned back 
> to the ipython prompt, to then be able to access the environment produced 
> by the script.
> 
> Is there some way to do that?  The -c option doesn't really work this way, 
> to my understanding.  This seems to especially be the case when the
> -qthread switch is also used.

If you simply say

ipython yourscript.py

it will work, with the caveat that sys.argv will include ipython as the first 
entry.  It would be possible to add a --run option which would work as follows:

ipython --foo --bar --run "yourscript.py --opt1 arg1"


The quotes would be needed to ease the construction of a sys.argv structure 
for the called script, independently of the real sys.argv given to ipython.

Given my enormous current backlog with ipython, this would fall at the end of 
the list though, since I think %run provides a reasonable working solution and 
the other things waiting are far more pressing.

Cheers,

f





More information about the IPython-user mailing list