将一个pdb命令转换为另一个pdb命令,但它不起作用

时间:2018-05-27 18:10:09

标签: python debugging pdb cpython

需要帮助,我正在尝试将JFrame frame = new JFrame("LoginExample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // fill the JFrame with the main GUI // .... frame.pack(); // create the LoginPanel JPanel here LoginPanel loginPanel = new LoginPanel(); // and display it in a JOptionPane here int result = JOptionPane.showConfirmDialog(frame, loginPanel, "User Log-In", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if (result == JOptionPane.OK_OPTION) { String userName = loginPanel.getUserName(); char[] password = loginPanel.getPassword(); // test to make sure code is working System.out.println("User Name: " + userName); // check for name/password validity here // ... if name/password OK, then show JFrame: frame.setLocationRelativeTo(null); frame.setVisible(true); } 的功能添加到c command命令,这些更改是进一步创建新命令所必需的。我不是我做错了,这两件事情是如何不同的第一件工作正常但第二件却不是,我只是改变行为

quit

但这不起作用,在这种情况下,self.do_quit甚至没有被调用。

db = pdb.Pdb()
db.do_c = db.do_quit
no = 3
db.runcall(fun,no)

我只是在简单的功能上运行

class dbg(pdb.Pdb):
    def custom_quit(self,arg):
        self.do_quit
db = dbg()
no = 3
db.do_c = db.custom_quit
db.runcall(fun,no)

在命令def fun(no): print("a") print("b") for i in range(0,no): print(i) return 'abc' 上它什么都不做。

1 个答案:

答案 0 :(得分:1)

在类中扩展方法的常用方法是使用相同的名称 调用super()来保存的方法(覆盖它) 原始方法功能:

因此,您可以将自定义方法更改为

class dbg(pdb.Pdb):
    def do_quit(self, arg):
        super().do_quit(arg)
        print('do something else')
        return(1)

和猴子补丁:

db.do_c = db.do_quit # do_quit as usual

查看pdb.py并搜索do_quit功能,然后您就可以了 明白你必须做的事情,或以某种方式保存, 包括return(1)