Feb-27-2017, 02:34 AM
is there a way to get the source file line number in some code? for example:
from __future__ import print_function # print a message with source line number n = get_source_code_file_line_number() n += 2 print('now printing at line',str(n))
Output:now printing at line 6
ORfrom __future__ import print_function for n in range(3) print('now printing at line',str(get_source_code_file_line_number())) print('now printing at line',str(get_source_code_file_line_number()))
Output:now printing at line 2
now printing at line 3
now printing at line 2
now printing at line 3
now printing at line 2
now printing at line 3
it's ok if it is based on starting at 1 instead of 0.