[IPython-user] newbie problem with introspection

Fernando Perez Fernando.Perez at colorado.edu
Wed Sep 27 02:27:04 CDT 2006


Please note that you must subscribe to ipython-user to post (too much spam).

This is mostly a limitation of python itself: it doesn't store the source for 
interactively defined objects anywhere at all, so there's nowhere to 
introspect for.  It would be possible to scan up the history searching for 
'def' lines, but it's a tricky operation because those may have happened in 
nested or dynamic places.  If you can contribute a patch to do this /robustly/ 
it's certainly welcome.

Cheers,

f


ipython-user-bounces at scipy.org wrote:
> The attached message has been automatically discarded.
> 
> 
> ------------------------------------------------------------------------
> 
> Subject:
> newbie problem with introspection
> From:
> Brent LEBACK <brent.leback at st.com>
> Date:
> Wed, 20 Sep 2006 10:12:35 -0700
> To:
> ipython-user at scipy.org
> 
> To:
> ipython-user at scipy.org
> 
> 
> There may be something very simple that I am missing.  Take it as a 
> documentation problem then.
> 
> In [1]: def foo(a,b):
>              return a+b
> 
> In [2]: ??foo
>                doesn't give me the source for foo
> 
> In[3]: import inspect
> In[4]: inspect.getsourcelines(foo)
>               doesn't give me the source for foo.
> 
> In[5]: %psource foo
>              No source found for foo
> 
> What is the best way to get the source for a function defined 
> interactively sometime in the past?  Search through In for "def foo"???
> 
> - Brent
> 
>  
> 


More information about the IPython-user mailing list