Python:在Finder / Windows资源管理器中打开模块源代码

时间:2014-08-13 18:36:42

标签: python shell

假设我在Python交互式shell中,我想查看我正在使用的模块的源代码。比方说,requests模块。我知道您可以使用inspect.getsource()在命令提示符下查看源代码。但是有没有python调用会在Finder或Windows资源管理器中打开该模块的源目录?

或者有没有办法让inspect.getsource()在终端外编辑器中打开源代码?

1 个答案:

答案 0 :(得分:1)

对于你的第一个问题'但是有没有python调用可以在Finder或Windows资源管理器中打开该模块的源目录?':你可以使用子进程打开你想要的文件夹:

import subprocess
mydir="c:\\"
subprocess.Popen('explorer '+mydir)

要在所需的编辑器中打开文件:如果您知道所需编辑器的路径,或者所需的编辑器已经在Windows路径中,您可以执行以下操作:

import subprocess
myfile="c:\\"
myEditor="gvim" #assuming gvim is in the path. If not use the full path
subprocess.Popen(myEditor + ' ' +mydir)
相关问题