How to get Current Function Name in python / example

How to get Current Function Name in python / example


def Print(*args): 
    func_name = "[" + sys._getframe(1).f_code.co_name + "] "
    for value in args:
        if type(value) is str:
            func_name = func_name + value
        else:
            func_name = func_name + str(value)
    
    print(func_name)


Based on where the current syntax is running,

Function called with current syntax :
sys._getframe(0).f_code.co_name

Function with current syntax :
sys._getframe(1).f_code.co_name

#Python #PyQt #Python print #function #function Name

No comments:

Post a Comment

Apartment Buying Guide 2025: Shocking Red Flags You Should NEVER Ignore!

 🏙️ Apartment Buying Guide 2025: Shocking Red Flags You Should NEVER Ignore! 🚨 Are you thinking about buying an apartment in 2025? 🏢  It’...