Skip to content

Instantly share code, notes, and snippets.

@ram1123
Last active January 24, 2026 14:04
Show Gist options
  • Select an option

  • Save ram1123/fd650fcab3f5d04aceb8fc6436ae888f to your computer and use it in GitHub Desktop.

Select an option

Save ram1123/fd650fcab3f5d04aceb8fc6436ae888f to your computer and use it in GitHub Desktop.
Get current line number in print statement using python program
import os
from inspect import currentframe
def get_linenumber():
cf = currentframe()
return cf.f_back.f_lineno
print("Current Line number: {}".format(get_linenumber()))
print("Current File name : {}".format(os.path.basename(__file__)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment