[英]Get current path when running Python from Notepad++
I run Python scripts in Notepad++ using this command我使用此命令在 Notepad++ 中运行 Python 脚本
cmd.exe /K "C:\InstallPython\python.exe" "$(FULL_CURRENT_PATH)"
it works, but it works not great.它有效,但效果不佳。 When I run
当我跑
exec(open("raw_ticker_list.lua").read())
it doesn't see the file, but it is in the same folder where the script lies.它没有看到该文件,但它位于脚本所在的同一文件夹中。 When I run
当我跑
import os
print(os.getcwd())
it prints它打印
How can I make python see files in current folder?如何让python看到当前文件夹中的文件?
Use this command instead:请改用此命令:
cmd.exe /K "cd /D "$(CURRENT_DIRECTORY)" & python "$(FULL_CURRENT_PATH)""
To recap, open the "Run" menu, select the "Run" entry, and enter the above command as "The Program to Run".回顾一下,打开“运行”菜单,选择“运行”条目,然后将上述命令输入为“要运行的程序”。 Possibly "Save…" it and assign a name (and keyboard shortcut) so that it permanently appears in the "Run" menu going forward.
可能“保存...”并分配一个名称(和键盘快捷键),以便它永久出现在“运行”菜单中。
What it does is, it opens a command window, changes the working directory to that of the script currently active in the editor (across hard drives, hence the /D
parameter), then runs the Python interpreter on the script, but keeps the command window open afterwards (the /K
parameter).它的作用是,它打开一个命令窗口,将工作目录更改为当前在编辑器中处于活动状态的脚本的工作目录(跨硬盘驱动器,因此使用
/D
参数),然后在脚本上运行 Python 解释器,但保留命令之后打开窗口( /K
参数)。
Use the full path to python.exe
instead of just python
in case it's not on the Windows search path for executables.使用
python.exe
的完整路径,而不仅仅是python
,以防它不在 Windows 可执行文件的搜索路径上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.