Wednesday, May 10, 2023

Python how to get the caller file name and line number

 import inspect

def info(msg):

    frm = inspect.stack()[1]

    print('frm is ',frm)

    mod = inspect.getmodule(frm[0])

    print(mod.__name__)

    

info('hello')


references:

https://stackoverflow.com/questions/1095543/get-name-of-calling-functions-module-in-python

No comments:

Post a Comment