Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有以下方法(在类或模块中,我认为这不重要):
def someMethod(): pass
我想在调用此方法时访问调用者的状态。
traceback.extract_stack只是给了我一些关于调用堆栈的字符串。
traceback.extract_stack
我想要这样的东西pdb,我可以在其中设置一个断点,someMethod()然后键入“u”以向上调用堆栈,然后检查系统的状态。
pdb
someMethod()
我想到了:
import inspect def callMe(): tag = '' frame = inspect.currentframe() try: tag = frame.f_back.f_locals['self']._tag finally: del frame return tag