[IPython-dev] Bug in revision 1029+

Jörgen Stenarson jorgen.stenarson at bostream.nu
Wed Jan 18 15:02:45 CST 2006


Hi

%run seems to have changed how it handles stack frames from revision 
1029. The attached python file a.py and b.py works when executed from 
the commandline with python a.py and python b.py respectively. See 
transcript below.

In revision 1028 %run b.py works but not a.py. 1029+ fails on both %run 
a.py and %run b.py. Importing a before executing %run a.py work, but not 
%run b.py. Importing b before makes both %run a.py and %run b.py work.

I use this technique to get a function that can return the source of the 
  module that the caller is in. If someone knows a better way I'd love 
to hear it.

I have done most of the testing of this on windows.


/Jörgen

transcript of commandline use:
 > python a.py
import inspect

def g():
     q=inspect.stack()[1]
     m=inspect.getmodule(q[0])
     src=inspect.getsource(m)
     return src

t=g()
print t

 > python b.py
import inspect

def g():
     q=inspect.stack()[1]
     m=inspect.getmodule(q[0])
     src=inspect.getsource(m)
     return src

t=g()
print t

----------------------------------------------------------------------
import a

print "-"*70
print a.g()





More information about the IPython-dev mailing list