print current line number python

Solutions on MaxInterview for print current line number python by the best coders in the world

showing results for - "print current line number python"
Juan Sebastián
07 Jun 2019
1#python3
2from inspect import currentframe, getframeinfo
3
4frameinfo = getframeinfo(currentframe())
5
6print(frameinfo.filename, frameinfo.lineno)
7
Kenan
25 Jan 2016
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()