linecache vs egg - reading line of a file in an egg

R. Bernstein rocky at
Sun Dec 21 04:18:44 CET 2008

Does linecache work with source in Python eggs? If not, is it
contemplated that this is going to be fixed or is there something else
like linecache that currently works?

Right now, I think pdb and pydb (and probably other debuggers) are
broken when they try to trace into code that is part of an egg.

Here's what I tried recently:

Using this egg:

I install that and look for the filename of one of the
functions. Here's a sample session:

>>> import tracer
>>> tracer
<module 'tracer' from '/usr/lib/python2.5/site-packages/tracer-0.1.0-py2.5.egg/tracer.pyc'>
>>> tracer.size
<function size at 0xb7c39a74>
>>> tracer.size.func_code.co_filename
>>> tracer.size.func_code.co_firstlineno

To read the source for, information from "Accessing Package

>>> from pkg_resources import resource_string
>>> print resource_string('tracer', '')

This gives me one long string which I can split and then index. 

Note that I used "" above, not
"build/bdist.linux-8686/egg/" How do tracebacks and things that
read frame information deal with the discrepency?

Before reinventing the wheel and trying to extend linecache to do
something like the above, has someone already come up with a solution?


More information about the Python-list mailing list