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
Handy if used in a common file - prints file name, line number and function of the caller:
import inspect def getLineInfo(): print(inspect.stack()[1][1],":",inspect.stack()[1][2],":", inspect.stack()[1][3])