1#python3
2from inspect import currentframe, getframeinfo
3
4frameinfo = getframeinfo(currentframe())
5
6print(frameinfo.filename, frameinfo.lineno)
7
1from inspect import currentframe
2
3def get_linenumber():
4 cf = currentframe()
5 return cf.f_back.f_lineno
6
7print "This is line 7, python says line ", get_linenumber()