我正在尝试在 Notepad++中复制 IDLE 的alt
+m
命令(在路径中打开一个模块)。sys
我喜欢 Notepad++ 进行编辑(而不是 IDLE),但这是我找不到的一个功能。
按下时alt+m
,我希望它运行一个请求模块的程序(这相当简单,所以我可以这样做)。我的问题是找到模块,然后在 Notepad++ 中打开它,而不是简单地运行程序。另外,我希望它在 Notepad++ 的同一个实例(同一个窗口)中打开,而不是一个新实例。
我试过这个:
import os
f = r"D:\my_stuff\Google Drive\Modules\nums.py"
os.startfile(f, 'notepad++.exe')
但是,我收到此错误:
Traceback (most recent call last):
File '_filePath_', line 3, in <module>
os.startfile(f, 'notepad++.exe')
OSError: [WinError 1155] No application is associated with the specified file for this operation: 'D:\\my_stuff\\Google Drive\\Modules\\nums.py'
我怎样才能解决这个问题?
另外,给定一个字符串,例如'nums.py'
,我怎样才能找到它的完整路径?它将位于以下两个文件夹之一中:'D:\\my_stuff\\Google Drive\\Modules'
或'C:\\Python27\Lib'
(也可能位于文件夹中的各个子'Lib'
文件夹中)。或者,我可以简单地做:
try:
fullPath = r'D:\\my_stuff\\Google Drive\\Modules\\' + f
# method of opening file in Notepad++
except (IOError, FileNotFoundError):
fullPath = r'C:\\Python27\\Lib\\' + f
# open in Notepad++
这不考虑子文件夹,而且看起来相当笨重。谢谢!