Python Configuration - Is there a mneumonic for script path and script filename?
Hi,
I find it a real PITA to have to create a cloned configuration for every Python script I am running. Plus I go to run my current script and I've forgotten to change the configuration dropdown and it runs the wrong code.
I want to create a generic configuration, say called Python 3.7, or MyDefaultConfiguration, or whatever
and specify this for the script path: $SCRIPT_PATH$
or alternatively: C:\Users\myuserid\Projects\myproject\somefolder\$SCRIPT_FILENAME$
and this generic configuration runs the current script I am editing.
I'm using IntelliJ IDEA but the same request goes for PyCharm as well.
Is this possible? If not consider this an enhancement request.
(I searched the help, these forums, and a generic Google search before posting, so if this is possible it's not obvious.)
Please sign in to leave a comment.
Hello,
There is an action "Run File in Python Console" which does exactly that. You can find it with Find action (Ctrl + Shift + A) and execute the currently selected file.
You can also assign a shortcut to that command.
Here is a related thread on our forum:
https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000781890-Quick-command-to-run-file-in-console-in-Pycharm-using-the-command-runfile-
Thanks. I find "Run File In Python Console" to have slightly less performance. I found the options to map "Run File in Python Console" to be extremely limited. I did map it to Cntl-Tab, Cntl-Tab, but that was not my preferred key combination.
However, I stumbled upon Cntl+Shift+F10, which creates a new configuration (if required - from a template???), activates that configuration, then executes the currently active script.
From Settings -> Keymap, it looks like Ctrl+Shift+F10 is mapped to Other, Run context configuration.
So Cntl+Shift+F10 is my go to key combination to submit my current Python script. I end up with a lot of duplicate, cloned, identical configurations, but I guess that's acceptable.
Under "Preferences | Keymap" you can assign "Run File In Python Console" action to any combination you want:
https://i.imgur.com/0s4Ks2W.png
If it conflicts with other key bindings, you can remove them.
"Under "Preferences | Keymap" you can assign "Run File In Python Console" action to any combination you want:"
See https://imgur.com/a/zYEm4rN.
Tell me how to map "Run File In Python Console" to Cntl-Alt-R or Cntl-Shift-R. For example, like I can do with Textpad, a popular inexpensive text editor.
Cntl-Alt and Cntl-Shift are easy-to-press keys on the keyboard, a bit easier than Cntl-Tab.
Hello,
Do not click "+" button at the right. Just press the key combination you want to assign: