How can I get the file name and line number in python script.
Exactly the file information we get from an exception traceback. In this case without raising an excep
import inspect file_name = __FILE__ current_line_no = inspect.stack()[0][2] current_function_name = inspect.stack()[0][3] #Try printing inspect.stack() you can see current stack and pick whatever you want