有什么方法可以返回方法文档字符串吗?
Is there any way of returning method documentation strings?
作为python3 returns中所有可用的可用方法中的dir()方法,
是否有任何方法可以将方法的文档(说明)作为字符串返回?
对于字典的 pop() 方法,它应该返回以下内容:
class MutableMapping(Mapping[_KT, _VT], Generic[_KT, _VT])
@overload def pop Possible types:
• (self: MutableMapping, k: _KT) -> _VT
• (self: MutableMapping, k: _KT, default: Union[_VT, _T]) -> Union[_VT, _T]
External documentation:
http://docs.python.org/3.6/library/
您可以使用 __doc__
属性访问函数的文档字符串:
➜ python
Python 3.6.4 (default, May 23 2018, 17:30:17)
Type "help", "copyright", "credits" or "license" for more information.
>>> print(dict.pop.__doc__)
D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
If key is not found, d is returned if given, otherwise KeyError is raised
[已解决]
正如所提到的评论和答案,help() 或 doc 都可以正常工作!
print(help(dict.pop))
print(dict.pop.__doc__)
作为python3 returns中所有可用的可用方法中的dir()方法, 是否有任何方法可以将方法的文档(说明)作为字符串返回?
对于字典的 pop() 方法,它应该返回以下内容:
class MutableMapping(Mapping[_KT, _VT], Generic[_KT, _VT])
@overload def pop Possible types:
• (self: MutableMapping, k: _KT) -> _VT• (self: MutableMapping, k: _KT, default: Union[_VT, _T]) -> Union[_VT, _T]
External documentation: http://docs.python.org/3.6/library/
您可以使用 __doc__
属性访问函数的文档字符串:
➜ python
Python 3.6.4 (default, May 23 2018, 17:30:17)
Type "help", "copyright", "credits" or "license" for more information.
>>> print(dict.pop.__doc__)
D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
If key is not found, d is returned if given, otherwise KeyError is raised
[已解决]
正如所提到的评论和答案,help() 或 doc 都可以正常工作!
print(help(dict.pop))
print(dict.pop.__doc__)