[IPython-user] pre/post-filters (was Evaluation of arbitrary expressions )
Frédéric Mantegazza
mantegazza at ill.fr
Thu Sep 15 09:13:16 CDT 2005
Le Mercredi 14 Septembre 2005 17:59, Fernando Perez a écrit :
> > Fernando, what about 2 additional hooks : one to execute arbitrary code
> > *before* the input string is executed, and one *after* ?
>
> They already exist :) They are called:
>
>
> In [3]: __IP.prefilter?
> Type: instancemethod
> Base Class: <type 'instancemethod'>
> String Form: <bound method InteractiveShell._prefilter of
> <IPython.iplib.InteractiveShell instance at 0x40061e8c>>
> Namespace: Interactive
> File: /usr/local/home/fperez/code/python/IPython/iplib.py
> Definition: __IP.prefilter(self, line, continue_prompt)
> Docstring:
> Calls different preprocessors, depending on the form of line.
>
>
> In [4]: __IP.outputcache.display?
> Type: instancemethod
> Base Class: <type 'instancemethod'>
> String Form: <bound method CachedOutput._display of
> <IPython.Prompts.CachedOutput instance at 0x403c0a2c>>
> Namespace: Interactive
> File: /usr/local/home/fperez/code/python/IPython/Prompts.py
> Definition: __IP.outputcache.display(self, arg)
> Docstring:
> Default printer method, uses pprint.
>
> This can be over-ridden by the users to implement special formatting
> of certain types of output.
>
> Display isn't very well documented (prefilter is, since the pysh and
> other examples show how to use it), but it's there.
> [...]
> Have a look at the pysh, tutorial or physics profiles :)
Oh, yes, I remember these hooks ! I planed to use prefilters to avoid the
user deleting internal objects of our PyMAD project... I still have to do
that :o/
--
Frédéric
More information about the IPython-user
mailing list