Pacific-Design.com

    
Home Index

1. Python

2. Debug

Python / Debug /

Python - Debug

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
import inspect

def PrintFrame():
  callerframerecord = inspect.stack()[1]    # 0 represents this line
                                            # 1 represents line at caller
  frame = callerframerecord[0]
  info = inspect.getframeinfo(frame)
  print info.filename                       # __FILE__     -> Test.py
  print info.function                       # __FUNCTION__ -> Main
  print info.lineno                         # __LINE__     -> 13


1
2
        frame = inspect.currentframe()
        print(frame.f_code.co_filename, "|", frame.f_lineno)