Feb-27-2017, 03:29 AM
Yes can use inspect for this.
Can make a function,then insert that function call will print line number.
Can make a function,then insert that function call will print line number.
import inspect def line_numb(): '''Returns the current line number in our program''' return inspect.currentframe().f_back.f_lineno # print a message with source line number n = 2 ; print('variable {} is at line {}'.format(n, line_numb())) print('now printing at line {}'.format(line_numb()))
Output:variable 2 is at line 8
now printing at line 9