How can I do an "if run from ipython" test in Python?
This is probably the kind of thing you are looking for:
def run_from_ipython():
try:
__IPYTHON__
return True
except NameError:
return False
The Python way is to use exceptions. Like:
try:
from IPython.Debugger import Tracer
debug = Tracer()
except ImportError:
pass # or set "debug" to something else or whatever