简体   繁体   中英

pdb from base class, get inside a method of derived class

I need to use pdb.set_trace() in the base class. 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. Also there is some pre processing of the arguments given to the run() method. So when pdb reaches the line,

q=self.run(arguments)

and I hit s it acts as if I have given the command next .

How can I get inside the derived class' run() method with pdb and debug the code over there?

It works absolutely fine if this example satisfies your problem:

base.py:

class basebase():
    print("something")
    def fun(self):
        print("hello")
    def getobj(obj):
        obj.fun()
print("run")

intermediate.py:

from base import basebase
class inter(basebase):
    print("nothing")

derived.py:

from intermediate import inter
class der(inter):
    def fun(self):
        print("world")

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. Problem solved!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM