Python equivt of __FILE__ and __LINE__

Jeff Schwab jeff at schwabcenter.com
Wed Feb 13 18:48:56 CET 2008


alain wrote:
> On Feb 12, 7:44 pm, Jeff Schwab <j... at schwabcenter.com> wrote:
> 
>> It still would be nice to have syntax as clean as __FILE__ and __LINE__.
> 
> There exists an undocumented builtin called __file__, but
> unfortunately no corresponding __line__

Drat!  So close!  Thanks for the info.  Oh well, I guess special cases 
aren't all that special, anyway.

Maybe a function called srcinfo.here() could return a tuple of the file 
name and line number, to allow syntax like:

     print("The program has reached %f:%d" % srcinfo.here())

Methods names like file_name() and line_no() aren't too hideous, either.



More information about the Python-list mailing list