onlyforbopi
2/4/2019 - 7:54 AM

Python.Logging.Inspect

Detailing the inspect module




import inspect



def firstfunc(a):
    
    print("In first func")
    
    # function name 
    print(inspect.stack()[0][3])
    
    # Caller Current Code line
    print(inspect.stack()[0][2])
    
    # Print Caller's name
    print(inspect.stack()[1][3])
    
    
    print(inspect.stack()[0])
    
    print(inspect.stack()[1])
    
    
    return a + a
    
def secondfunc(b):
    print(inspect.stack()[0][3])
    print(inspect.stack()[1][3])
    print( b + 10 )
    
    def thirdfunc(c):
        print(inspect.stack()[0][3])
        print(inspect.stack()[1][3])
    
        return c**2
        
    print ( b + thirdfunc(b) )
    
    
firstfunc(5)
secondfunc(5)