Python equivt of __FILE__ and __LINE__
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Tue Feb 12 12:45:55 EST 2008
En Tue, 12 Feb 2008 14:41:20 -0200, Jeff Schwab <jeff at schwabcenter.com>
escribi�:
> def line():
> try:
> raise Exception
> except:
> return sys.exc_info()[2].tb_frame.f_back.f_lineno
> def file():
> return inspect.currentframe().f_code.co_filename
It's not a good idea to shadow the file type; I'd suggest current_file and
current_line.
file() should return inspect.currentframe().f_back.f_code.co_filename,
else you're using the filename for file() itself, not the caller's
And why the assymetry? Using try/except might help Jython, but that should
be an implementation detail of inspect.currentframe() anyway. line()
should just return inspect.currentframe().f_back.f_lineno
--
Gabriel Genellina
More information about the Python-list
mailing list