Skip to main content
 首页 » 编程设计

python之为什么ipdb下的help()命令报错

2024年10月24日8zengkefu

在 ipython 中,我可以发出以下命令并提供帮助:

In [1]: help(["foo", "bar", "baz"]) 
 
class list(object) 
 |  list() -> new empty list 
 |  list(iterable) -> new list initialized from iterable's items 
 | 
 |  Methods defined here: 
 | 
 |  __add__(...) 
 |      x.__add__(y) <==> x+y 
 | 
 |  __contains__(...) 
 |      x.__contains__(y) <==> y in x 
... 

但是当我在 ipdb 中做同样的事情时,我得到一个错误:

ipdb> help(["foo", "bar", "baz"]) 
*** No help on (["foo", "bar", "baz"]) 

为什么?

请您参考如下方法:

help 是pdb中的一个特殊命令。您需要显式调用 p help(obj) 而不是 help(obj)。如果您在 pdb 中单独调用 help,您会看到不同之处。