__LINE__?

Adrian Eyre a.eyre at optichrome.com
Wed Nov 3 18:17:56 CET 1999


> Is there an equivalent of the C __LINE__ macro in Python to get the
> currentline number?

import sys

def what_line_am_i_on():
    try:
        raise "Hack"
    except:
        return sys.exc_info()[2].tb_frame.f_back.f_lineno

print "This is line " + str(what_line_am_i_on())

--------------------------------------------
Adrian Eyre <mailto:a.eyre at optichrome.com>
Optichrome Computer Solutions Ltd
Maybury Road, Woking, Surrey, GU21 5HX, UK
Tel: +44 1483 740 233  Fax: +44 1483 760 644
http://www.optichrome.com 
--------------------------------------------





More information about the Python-list mailing list