[IPython-User] A robust way to grab the IPython shell reference within a script / module
Thu Mar 15 04:12:42 CDT 2012
Simon Ratcliffe and I stumbled upon what may be the shortest, most robust and backwards compatible way to obtain a reference to the IPython shell from within a script or module (used e.g. to add custom tab completers for our objects):
# IPython 0.11 and above
ip = get_ipython()
# IPython 0.10 and below (or normal Python shell)
ip = __builtins__.get('__IPYTHON__')
if ip is not None:
# We are within IPython, so set up those completers
This seems to work from at least 0.8.4 all the way to 0.12 (and beyond, I hope). Any comments, scorn or ridicule ("__builtins__? Are you nuts?") are very welcome.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the IPython-User