[英]pdb from base class, get inside a method of derived class
I need to use pdb.set_trace()
in the base class. 我需要在基类中使用pdb.set_trace()
。 It has a method: 它有一个方法:
def run(self, *args, **kwargs):
raise NotImplementedError
Since this base class is derived by many subclasses I don't know before hand which class' run()
method I need to get inside. 由于此基类是由许多子类派生的,因此我事先都不知道需要进入哪个类的run()
方法。 Also there is some pre processing of the arguments given to the run()
method. 还可以对run()
方法的参数进行一些预处理。 So when pdb reaches the line, 因此,当pdb达到要求时,
q=self.run(arguments)
and I hit s
it acts as if I have given the command next
. 然后按s
,就好像我next
命令一样。
How can I get inside the derived class' run()
method with pdb and debug the code over there? 如何使用pdb进入派生类的run()
方法并在那里调试代码?
It works absolutely fine if this example satisfies your problem: 如果此示例满足您的问题,则可以正常工作:
base.py: base.py:
class basebase():
print("something")
def fun(self):
print("hello")
def getobj(obj):
obj.fun()
print("run")
intermediate.py: intermediate.py:
from base import basebase
class inter(basebase):
print("nothing")
derived.py: derived.py:
from intermediate import inter
class der(inter):
def fun(self):
print("world")
main.py: main.py:
from derived import der
from base import basebase
obj=der()
basebase.getobj(obj)
Now simply add pdb.set_trace
to the getobj()
method. 现在,只需将pdb.set_trace
添加到getobj()
方法。 Problem solved! 问题解决了!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.