Python 内省:函数参数的描述
是否有一个类似于 dir() 的模块工具可以告诉我给定函数采用哪些参数?例如,我想做类似 dir(os.rename) 的事情,并让它告诉我记录了哪些参数,这样我就可以避免在线检查文档,而只使用 Python 脚本接口来做到这一点。
Is there is a tool similar to dir()
for modules that will tell me what parameters a given function takes? For instance, I would like to do something like dir(os.rename)
and have it tell me what parameters are documented so that I can avoid checking the documentation online, and instead use only the Python scripting interface to do this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我意识到您对
help(thing)
或thing.__doc__
更感兴趣,但是如果您尝试进行编程内省(而不是人类可读的文档)要了解如何调用函数,您可以使用inspect
模块,正如这个问题。I realize that you're more interested in
help(thing)
orthing.__doc__
, but if you're trying to do programmatic introspection (instead of human-readable documentation) to find out about calling a function, then you can use theinspect
module, as discussed in this question.help(thing)
漂亮地打印模块、方法等中的所有文档字符串......help(thing)
pretty prints all the docstrings that are in the module, method, whatever ...