Supporting #line directives

Michael Hudson mwh21 at
Mon Mar 6 18:20:01 CET 2000

Andrew Csillag <drew.csillag at> writes:

> I don't really want a debugger for it (although it would be neat), I
> just want to make it so that I don't have to do so much work in order to
> render a traceback that shows source lines in the original source file. 
> Python's bytecode already has a SET_LINENO instruction, if there were a
> SET_FILENAME instruction, that would handle it nicely (of cource ceval.c
> would probably require a bit of modification, but that's just a "simple
> matter of programming" <0.3 wink>).
> Unfortunately, introspection doesn't help a bit here.  With
> introspection I can find out where functions and classes are defined in
> python source, but not in the original (non-python) source.

>>> def f():
...   raise "hiya!"
>>> from bytecodehacks import common
>>> import new
>>> f=new.function(common.copy_code_with_changes(
...   f.func_code,filename="whatever.c"),f.func_globals)
>>> f()
Traceback (innermost last):
  File "<stdin>", line 1, in ?
  File "whatever.c", line 2, in f

Is this helping?


very few people approach me in real life and insist on proving they are
drooling idiots.                         -- Erik Naggum, comp.lang.lisp

More information about the Python-list mailing list