__LINE__ and __FILE__ functionality in Python?

Maric Michaud maric at aristote.info
Sun Aug 13 09:17:33 EDT 2006


Le dimanche 13 août 2006 14:18, John Machin a écrit :
> I don't usually go for one-liners, especially ugly ones like
> "inspect.stack()[1][1:3]" but it avoids the risk of hanging on to a
> reference to the frame object -- see the warning in the inspect docs.

Yes, my mistake, thanks for pointing this out, my suggestion should have been 
more accurate :

import inspect

try :
	c=inspect.currentframe()
	log_msg(c.f_lineno, c.f_code.co_filename)
finally :
	del c

or shorter ;

from inspect import currentframe
log_msg(currentframe().f_lineno,
                currentframe().f_code.co_filename)


-- 
_____________

Maric Michaud
_____________

Aristote - www.aristote.info
3 place des tapis
69004 Lyon
Tel: +33 426 880 097



More information about the Python-list mailing list