有没有办法从 python 控制台中查看模块的源代码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2055110/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
is there a way to view the source of a module from within the python console?
提问by tehryan
if I'm in the python console and I want to see how a particular module works, is there an easy way to dump the source?
如果我在 python 控制台中并且想查看特定模块的工作方式,是否有一种简单的方法可以转储源代码?
回答by Alok Singhal
回答by Micha? Marczyk
Using IPython, you can do this:
使用 IPython,你可以这样做:
In [1]: import pyparsing
In [2]: pyparsing.Word??
...and the source will be displayed, if possible. I guess this must use inspect
under the hood, but the added convenience of ? / ?? is fantastic.
...如果可能,将显示源。我想这必须inspect
在引擎盖下使用,但是 ? / ?? 太棒了。