Supporting #line directives

Andrew Csillag drew.csillag at starmedia.net
Mon Mar 6 12:28:14 EST 2000


Warren Postma wrote:
> 
> > I've lately been using python as a target language for various purposes
> > and I was wondering if anybody has thought of supporting something like
> > C's #line directives which would make it possible to (without hacking an
> > exception renderer to badly) show the lines
> 
> I suggest you look at how they write "source level debuggers" in Python.
> Python has so much introspection that I'm sure you could write at least your
> own debugger and get some of the functionality you want not from macros, but
> from introspection.

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.
-- 
print(lambda(q,p):'pmt:$%0.2f'%(q*p/(p-1)))((lambda(a,r,n),t:(a*r/
t,pow(1+r/t,n*12)))(map(input,('amt:','%rate:','years:')),1200.0))




More information about the Python-list mailing list