Python equivalent of #line?

Bengt Richter bokr at oz.net
Sun May 25 15:03:57 EDT 2003


On 25 May 2003 09:37:31 -0400, pinard at iro.umontreal.ca (=?iso-8859-1?q?Fran=E7ois_Pinard?=) wrote:

>[Gerrit Holl]
>
>> 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?
>
>> Why do you want that?
>
>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.
>
>It would be nice if the Python compiler was supporting such directives.
>Even if I agree many people would not need it, it would be extremely useful
>to those who do.  It would be also useful for developers being able to ask
>the Python generator to disregard those `#line' directives when the time
>comes to debug the Python generators themselves.
>
If you were e.g., generating gen.py from gdata.txt, you could at the same time
generate a vim tag file to translate key line locations of gen.py to gdata.txt
locations (since you would know both line numbers from your reading and writing).
UIAM, a line in a tag file of the form (note tab delimiters mandatory by default):

gen123\tgdata.txt\t456

would let you start vim and type :ta /gen123 and get right to tgdata.txt at line 456

If you made the tags file "gen.tags" instead of the default "tags" you could start vim
at the first tagged line something like

    vim -c ":set tags=gen.tags|ta /gen"

and then step through them all with :tn or go to a particular one with :ta /genXXX

Regards,
Bengt Richter




More information about the Python-list mailing list