Adjusting filename and line number

banshee.welton at gmail.com banshee.welton at gmail.com
Thu Dec 18 19:40:19 CET 2008


Hello,

  I'm working with some embedded python and would like to be able to
adjust the reported filename and line number of some embedded user-
written code so that errors returned coincide with things the user
might actually be familiar with.

  In perl I could do this by adjusting the filename and line within a
script like so:

foo.pl
------
#!/usr/bin/env perl
#line 1000 "myfile.txt"
this is a syntax error

$ perl foo.pl
Can't locate object method "a" via package "syntax" (perhaps you
forgot to load "syntax"?) at myfile.txt line 1000.

  For what it's worth, the same directive also works as a "C"
preprocessor macro.

  I have searched for ways of managing this in python, but so far have
not found any way of accomplishing this.  Anyone know how it could be
done?

  Thanks




More information about the Python-list mailing list