Python equivalent of #line?

Erwin S. Andreasen erwin at andreasen.com
Mon May 26 09:45:29 EDT 2003


pinard at iro.umontreal.ca (François Pinard) writes:

> > Edward C. Jones schreef op zondag 25 mei om 14:27:34 +0000:
> > > C has a preprocessor command
> > >   #line n "filename"
> > > Can I do this in Python?

> For the case you drive generation of Python code from lengthy data files.
> You may want tracebacks to refer to your data files instead of generated
> Python code, which is not your real sources, nor where you will point your
> editor for making the real corrections.

I've used a hack to achieve this when compiling pieces of Python code
interspersed through an XML file: first of all, use compile() which
can be passed a filename, and then simply pad the start of the source
being compiled with blank lines, to align it with the real line
numbers in the original file.


-- 
===============================================================
<erwin at andreasen.org>                           Herlev, Denmark     
<URL:http://www.andreasen.org/>                             <*>   
===============================================================





More information about the Python-list mailing list