[IPython-user] detecting %run
Fernando Perez
Fernando.Perez at colorado.edu
Wed Sep 14 16:14:37 CDT 2005
Glen W. Mabey wrote:
> I have a script that I would like to see behave differently when invoked
> through the generic shell as
> python the_script.py
> versus via the %run magic command. Is there a variable or
> something
> that could be tested to know which invocation was used?
Yes, IPython sticks a reference to itself in the builtin namespace:
In [1]: __IPYTHON__
Out[1]: <IPython.iplib.InteractiveShell instance at 0x40061e0c>
for this very purpose. So you can:
try:
__IPYTHON__
# you are in ipython
except NameError:
# you're not inside ipython
Cheers,
f
More information about the IPython-user
mailing list