Skip to content

Instantly share code, notes, and snippets.

@GadgetSteve
Last active June 26, 2022 08:28
Show Gist options
  • Save GadgetSteve/fcfb3406ad3fe6a8adea735dcb283d31 to your computer and use it in GitHub Desktop.
Save GadgetSteve/fcfb3406ad3fe6a8adea735dcb283d31 to your computer and use it in GitHub Desktop.
How to get the line number in python
# coding: utf-8
# Originally from a tweet by Ned Batchelder @nedbat
import inspect
def __line__():
""" Return the current line number. """
return inspect.currentframe().f_back.f_lineno
if __name__ == "__main__":
print(f"At {__line__()} of {__file__}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment