简体   繁体   English

将键盘快捷键添加到以当前文件为参数的 run.py 脚本

[英]Add keyboard shortcut to run .py script with current file as argument

Assuming I have a .py script in ~/Scripts/script.py , how can I run it with the currently opened file in PyCharm 2020.3 Professional?假设我在~/Scripts/script.py中有一个.py脚本,如何使用 PyCharm 2020.3 Professional 中当前打开的文件运行它?

What I simply need is to bind a keyboard shortcut to a python ~/Scripts/script.py <current_file> command and see the output in console.我只需要将键盘快捷键绑定到python ~/Scripts/script.py <current_file>命令并在控制台中查看 output。

Edit: I guess I need a PyCharm equivalent of https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner编辑:我想我需要一个 PyCharm 相当于https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner

Simplest way would be to get AutoHotKey and use that, as it has a lot of functionality, and because I don't think you can set extra shortcuts in PyCharm, both versions.最简单的方法是获取 AutoHotKey 并使用它,因为它有很多功能,而且我认为你不能在 PyCharm 中设置额外的快捷方式,两个版本。 You could try this though in a separate file:您可以在单独的文件中尝试此操作:

import os
os.system("path/to/script.py path/to/otherfile.py")

or if you need to give the second file as STDIN or input:或者如果您需要将第二个文件作为 STDIN 或输入:

import os
os.system("path/to/script.py<path/to/otherfile.py)

Warning though, the second will turn your otherfile.py into STDIN and therefore it will be readable line by line with input() Extra但是警告,第二个会将您的 otherfile.py 转换为 STDIN,因此它可以通过input() Extra 逐行读取
AHK Script for you:适合您的 AHK 脚本:

#SingleInstance, force
; # is for windows key, ! is for Alt key, ^ is for control key, + is for Shift key
^+r:: ; Will use Ctrl+Shift+R
Run, python path/to/script.py path/to/otherfile.py
return

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM