##// END OF EJS Templates
- Cleanup [1786], which went in with unfinished stuff by accident....
- Cleanup [1786], which went in with unfinished stuff by accident. - Revert [1785] and replace it by installing our own quitter in place of the builtin (for all py versions). This obviates the need for [1785] and gives a cleaner exit. - Fix ipdb to work with python 2.5, and update ipdb color schemes with %colors. - irunner improvements, mostly for use as a doctest runner.

File last commit:

r0:6f629fcc
r368:ede41cba
Show More
example-magic.py
36 lines | 1.3 KiB | text/x-python | PythonLexer
"""Example of how to define a magic function for extending IPython.
The name of the function *must* begin with magic_. IPython mangles it so
that magic_foo() becomes available as %foo.
The argument list must be *exactly* (self,parameter_s='').
The single string parameter_s will have the user's input. It is the magic
function's responsability to parse this string.
That is, if the user types
>>>%foo a b c
The followinng internal call is generated:
self.magic_foo(parameter_s='a b c').
To have any functions defined here available as magic functions in your
IPython environment, import this file in your configuration file with an
execfile = this_file.py statement. See the details at the end of the sample
ipythonrc file. """
# fisrt define a function with the proper form:
def magic_foo(self,parameter_s=''):
"""My very own magic!. (Use docstrings, IPython reads them)."""
print 'Magic function. Passed parameter is between < >: <'+parameter_s+'>'
print 'The self object is:',self
# Add the new magic function to the class dict:
from IPython.iplib import InteractiveShell
InteractiveShell.magic_foo = magic_foo
# And remove the global name to keep global namespace clean. Don't worry, the
# copy bound to IPython stays, we're just removing the global name.
del magic_foo
#********************** End of file <example-magic.py> ***********************