[IPython-user] ? / pylab question

Fernando Perez fperez.net at gmail.com
Wed Jan 10 01:57:21 CST 2007


On 1/10/07, belinda thom <bthom at cs.hmc.edu> wrote:

> I've been using IPython w/the -pylab flag. Why does
>
>    In [1]: draw_if_interactive?
>
> produce:
>
>    Type:           function
>    Base Class:     <type 'function'>
>    String Form:    <function wrapper at 0x3112c30>
>    Namespace:      Interactive
>    File:           /Library/Frameworks/Python.framework/Versions/2.4/
> lib/python2.4/site-packages/IPython/genutils.py
>    Definition:     draw_if_interactive(*args, **kw)
>    Docstring:
>        <no docstring>
>
> I've looked at genutils --- no draw_if_interactive function lives
> there. It does live in Shell.py, but as:
>
>    import matplotlib as pylab
>    self.pylab = pylab
>    self.pylab.draw_if_interactive

In [4]: draw_if_interactive??
Type:           function
Base Class:     <type 'function'>
String Form:    <function wrapper at 0x42ff6764>
Namespace:      Interactive
File:           /home/fperez/usr/lib/python2.4/site-packages/IPython/genutils.py
Definition:     draw_if_interactive(*args, **kw)
Source:
def wrapper(*args,**kw):
        wrapper.called = False
        out = func(*args,**kw)
        wrapper.called = True
        return out

It's a runtime wrapper to control certain things, and this confuses
the introspection mechanism.  From the code:

        # We need to detect at runtime whether show() is called by the user.
        # For this, we wrap it into a decorator which adds a 'called' flag.
        self.pylab.draw_if_interactive =
flag_calls(self.pylab.draw_if_interactive)

HTH,

f


More information about the IPython-user mailing list