Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCharm focus Python Console for input upon run

Tags:

python

pycharm

In PyCharm 2018.2.5 (Community Edition), I have bound a keyboard shortcut to "Run File in Console". This launches opens the console and runs the file, but does not focus the console for input and anything I type goes into my code. (Sometimes when I use the switcher to focus the Python console it will try to search console variables when I type.)

Is there a way to automatically focus the Python console for input when it is launched?

like image 732
user9811991 Avatar asked Nov 16 '18 21:11

user9811991


2 Answers

No for PyCharm there is no way to automatically focus the Python console for input when it is launched.

In Notepad ++ i can do the following.

  1. Enter my code
  2. press shift+a to execute a macro which saves the file and execute it with Python 2.7 (or 3). I also made this macro a menu item.
  3. When the console runs and the script asks for input you are already in focus and can directly put in our entry without having to click and highlight the window or so as it is necessary in PyCharm.

So the step between writing the code and executing it to see what it does exactly one hotkey. Its not one hotkey and a mouse click or what ever no.... its exactly one press of a button. This makes learning very effective because there are no detours.

I looked long in PyCHarm but i could not find this functionality or a workaround. So the answer to your question is "With PyCharm this is not possible."

Here is how to do it in Notepad ++.

  • Download Notepad ++
  • In N++ install the NppExec Plugin.
  • Create the "save and run in python" macro: In NppExec create a script as shown here:

    NPP_CONSOLE 0 
    npp_save 
    npp_run cmd /K C:\Python27\python.exe "$(FULL_CURRENT_PATH)"
    
  • Save your macro script as say "Save and run in Python Selfmade"
  • In the hotykeys menu assign your macro to a new hotkey.
  • In the Npp_Exec menu click on Advanced Options and create a menu entry for your macro. To do this select the script you created under "Associated Script" and then click on "Add/Modify"

Another editor that offers you this quick and direct run functionality is "Atom" with its many plugins.

like image 81
jay123 Avatar answered Sep 21 '22 06:09

jay123


The shortcut to switch between the code and console is Alt+4; by clicking on the console or using this shortcut, future consoles you open will be selected by the input.

like image 43
mhoffman2016 Avatar answered Sep 21 '22 06:09

mhoffman2016