[IPython-dev] Towards IPython 1.0, the famous big cleanup

Jack Moffitt jack at xiph.org
Fri Apr 15 14:33:24 EDT 2005


> magic involves binding by hand an instance method with a special name, for 
> example:
> 
> from IPython.iplib import InteractiveShell
> 
> def magic_runbatch(self, parameter_s=''):
>     """ runbatch magic command.
>     """
>     try:
>         fileobj = open(parameter_s,'r')
>     except:
>         print "Error: could not open file",parameter_s
>         return
>     else:
>         self.shell.runlines(fileobj.read())
> 
> InteractiveShell.magic_runbatch = magic_runbatch
> del magic_runbatch
> 
> What I envision, is something cleaner, more like:
> 
> __IPYTHON__.set_new_magic(your_function,optional_name='mymagic',opt_args=...)

Not that I like the new decorator syntax, but something like:

@InteractiveShell.magicmethod
def run_batch(...)
   ...

Is pretty easy to read and grok.

jack.




More information about the IPython-dev mailing list