Skip to content

Instantly share code, notes, and snippets.

@whoiscarlo
Created February 26, 2015 20:41
Show Gist options
  • Save whoiscarlo/6afd4ca4be66db4a1364 to your computer and use it in GitHub Desktop.
Save whoiscarlo/6afd4ca4be66db4a1364 to your computer and use it in GitHub Desktop.
Fucntion to grab the current line number python
"""This provides a lineno() function to make it easy to grab the line
number that we're on.
Danny Yoo ([email protected])
"""
import inspect
def lineno():
"""Returns the current line number in our program."""
return inspect.currentframe().f_back.f_lineno
if __name__ == '__main__':
print "hello, this is line number", lineno()
print
print
print "and this is line", lineno()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment