Last active
June 26, 2022 08:28
-
-
Save GadgetSteve/fcfb3406ad3fe6a8adea735dcb283d31 to your computer and use it in GitHub Desktop.
How to get the line number in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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