如何从记事本中运行 python 脚本?

发布于 2024-08-24 01:52:21 字数 126 浏览 9 评论 0原文

当我使用 textmate 时,我只需点击“apple+r”,程序就会被解释。如何从 notepad++ 中运行程序?我看到 F5 代表“运行”,但将其指向 Python.exe 只是打开一个运行 python 的终端。它不运行我的脚本。

When I'm using textmate, I simply hit "apple+r" and the program gets interpreted. How can I run a program from within notepad++? I see that F5 is for "Run", but pointing that to Python.exe simply opens up a terminal with python running. It does not run my script.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

清秋悲枫 2024-08-31 01:52:21

插件 NppExec 执行 (F6) 比普通运行 (F5) 功能强大得多。通过插件、插件管理器安装 NppExec。然后在F6中添加/保存以下内容:

NPP_SAVE
cd "$(FULL_CURRENT_PATH)"
C:\Python34\python.exe -u "$(FULL_CURRENT_PATH)"

在插件NppExec控制台输出过滤器中(Shift+F6
添加以下HighLight蒙版:

*File "%FILE%", line %LINE%

确保选中它,并将其设置为红色并加下划线。

在“F6/execute”时,错误将突出显示并可单击!

这适用于 NPP568,可能更旧。

Plugins NppExec Execute (F6) is much more powerful than plain Run (F5). Install NppExec via Plugins, Plugin Manager. Then in F6 add/save the following:

NPP_SAVE
cd "$(FULL_CURRENT_PATH)"
C:\Python34\python.exe -u "$(FULL_CURRENT_PATH)"

In Plugins NppExec Console output filters (Shift+F6)
add the following HighLight mask:

*File "%FILE%", line %LINE%

Make sure it's checked, and make it e.g. red and underlined.

Upon "F6/execute" errors will be highlighted and clickable !

This works in NPP568, possibly older.

世界如花海般美丽 2024-08-31 01:52:21

您需要将 FULL_CURRENT_PATH 环境变量传递给程序,如 记事本++维基

python "$(FULL_CURRENT_PATH)"

You need to pass through the FULL_CURRENT_PATH environment variable to the program, as described in the notepad++ wiki:

python "$(FULL_CURRENT_PATH)"
双手揣兜 2024-08-31 01:52:21

您可以使用 PyNPP 插件 (https://github.com/mpcabd/PyNPP) 来实现此目的。

我知道这已经过时了,但答案是为来自搜索的人提供的。

You can use PyNPP Plugin (https://github.com/mpcabd/PyNPP) to achieve this.

I know this is old but the answer is for people coming from search.

少女情怀诗 2024-08-31 01:52:21

也可以使用 pdb

上面的答案对于让它工作非常有用。然而,一旦我可以运行 python 程序,我还需要与它们交互。我发现了两件事。

  1. 如果您希望与程序交互(例如提供命令行输入),请使用“python -u -i $(FULL_CURRENT_PATH)”。
  2. 要使用很棒的PDB,请使用“ python -u -m pdb $(FULL_CURRENT_PATH)" 然后您也可以轻松调试程序。 :-) 喜欢它!!

possible to use pdb too

The answers above were very useful to get it working. However, once i could run the python programs, I also needed to interact with them. Two things I found out.

  1. Use "python -u -i $(FULL_CURRENT_PATH)" if you wish to interact with your program (like giving command line inputs).
  2. to use the awsome PDB, use "python -u -m pdb $(FULL_CURRENT_PATH)" and then you can easily debug your programs as well. :-) loving it!!
2024-08-31 01:52:21

如果您有 NppExec 插件(默认情况下),请按 F6 并添加执行脚本的命令

python /path/to/script.py

if u have the NppExec plugin (is by default) hit F6 and add the command that exec your script

python /path/to/script.py
过度放纵 2024-08-31 01:52:21

除非我遗漏了一些东西,否则讨论 NppExec 的其他答案没有提供一种通过单次击键运行脚本的方法,或者(按下 F6 时总是弹出执行对话框,必须先接受该对话框)脚本已运行)。

完成 bjornhb 的回答中的步骤后,您只需按一次键即可运行脚本:

  1. 在 Plugins->NppExec 下->高级选项创建一个新的菜单项。我只是将我的命名为Python。在关联脚本下拉框中选择之前保存的脚本,然后单击添加/修改。单击确定
  2. 重新启动 Notepad++
  3. 在“设置”->“快捷方式映射器”下,单击顶部的“插件命令”选项卡。向下滚动并在左侧找到您的命令名称。双击命令名称旁边的“快捷方式”列中的白色框内。选择适当的键(或组合)并接受。按快捷键将运行脚本,无需进一步输入。

Unless I'm missing something, the other answers discussing NppExec do not provide a way to run the script with a single keystroke or (the execute dialogue box always pops up when F6 is pressed which must be accepted before the script is run).

After completing the steps in bjornhb's answer the following will allow you to run scripts with just one keystroke:

  1. Under Plugins->NppExec->Advanced Options create a new Menu Item. I simply named mine Python. Select the script which was saved earlier in the Associated script dropdown box and click Add/Modify. Click OK.
  2. Restart Notepad++
  3. Under Settings->Shortcut Mapper click the Plugin commands tab at the top. Scroll down and find your command name on the left hand side. Double click inside the white box in the Shortcut column next to your command name. Select an appropriate key (or combination) and accept. Pressing the shortcut key(s) will run the script without further input.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文