I've just started learning python from scratch
I've installed 3.6 for windows
On the IDLE shell how can I get the shortcut for retyping what you previously executed (this is usually the up button)?
and also there is usually a drop down list for when you're typing something and python shows a list of what you might be about to type and you can select and it types it for you?
example:
thanks
To get last command executed, use alt+p.
Otherwise, under the Options menu, go to Configure IDLE >> Keys, and set history-next/history-previous to the keys you wish to use.
Press enter on the line you want to retype
EDIT
To show autocomplete window press TAB.
There's a default delay in 2 seconds. You can set popupwait to 0 in Options->Configure IDLE->Extensions->AutoComplete. Take into accout that you should restart you shell to activate new settings.
For Python 3.6 on Windows, specifically.
Shortcut to get what you typed previously: Alt + P
To get auto completion: Ctrl + space
Also, you can navigate the configuration for these Shortcut Keys in the Navigation bar.
All of the keybindings can be changed in Options > Configure IDLE > Keys. The ones in my answer are the default on Windows.
Cycle commands backwards: Alt+p
Cycle commands forwards: Alt+n
Alternatively, put cursor on a line you want to re-run and press Enter
Pop-up auto completion: Tab (or Ctrl+Space)
Alternatively, just set Options > Configure IDLE > General > Completions Popup Wait to 0, for the autocompletion to always come up automatically
Related
I have a problem with python autocomplete in visual studio code. The only way I can trigger the autocomplete function is with the Tab or Enter key. Brackets and dot does not have any effect (or better it just hides the suggestion box and puts the bracket in place on the unfinished word e.g. -> typing pr in the editor would display the suggestion box with print as the first choice, if i then press bracket i end up with pr() instead of print())
I presume there should be some settings so autocomplete would act "normally" but I can't find it.
This is set by the shortcut key. Open the Default Keyboard Shortcuts (File > Preferences > Keyboard Shortcuts) and search for "acceptSelectedSuggestion". You will see that there are only two settings by default, the Tab and Enter keys.
If you want to add other buttons to trigger typing intellisense, right-click on one of the settings and select Add Keybinding,
then press the button you want to set, and press Enter to save.
I think you don't need to use the python autocomplete extension. You can just use the Python extension.
Tab or enter is required to actually make a selection. Otherwise, you could have custom function printStuff, and typing pr( would not necessarily pick the right one.
From what I can tell, PyCharm works the exact same way, so unclear what "acts normal" means in this context.
The question is regarding Visual Studio Code (VSCode from here) and python VSCode extension that finds and runs py.test tests.
Is it possible to assign some shortcut to run current (under cursor) test method and/or test class?
I really like the ability to run single test straight from VSCode, but my workflow is not optimal since it is necessary to click it and just use some shortcut.
This image shows the buttons that appear when tests are found and can be run. I would like to know if it is possible to just use some custom shortcut instead of clicking this buttons.
Try Test Explorer UI and Python Test Explorer for Visual Studio Code.
The command list:
However, run-test-at-cursor doesn't work for me. I use run-file. Moreover, maybe you should join workbench.action.files.save, test-explorer.reload, and test-explorer.run-test-at-cursor with a macro extension.
Go to File > Preferences > Keyboard Shortcuts
In the searchbox, type python
All Python commands will be displayed below.
Select the command you want to add a key binding and click on the '+' button. Enter your preferred key combination in the new window.
Starting with VSCode 1.59 and the new Testing API (?) there are now these two new commands:
Run Test at Cursor
Debug Test at Cursor
Assuming the unit test you want to repeatedly run is selected in the Test sidebar (which you can do just by clicking on it), I've found a keyboard-driven option that doesn't require an extension to repeat running it. From anywhere in VS Code, type:
shift+cmd+i, which for me is bound to the command workbench.view.extension.test.
(Optional) Note that annoyingly, you sometimes have to press shift+cmd+i a second time to select the unit test in question (this seems like a bug to me - this happens with all Side Bar views)
Tab-Tab-Space (i.e. Tab, then Tab, then Space). The two tabs select the little bug symbol on your test and the Space kicks off another debug run of the selected test.
Here's how the screen should look after the two Tab presses:
and then the Space "clicks" the selected debug button.
With these 2-3 steps you can repeat this unit test ad infinitum.
HTH
In my case, a lot of test functions already have shortcuts:
I also added a shortcut to get to the test bench with the keyboard shortcuts utility.
Run/Debug/Interactive console in VSCode Editor ==>
File -> Preferences -> Extensions -> Robot > Code Lens: Enable/Disable
File -> Preferences -> Extensions -> Robot: Variables -> Edit in settings.json
need to add "ENV":"DEV"
Restart VS Code editor
Is there any way to make it so that I can press run and start typing the answer to the input prompt? It doesn't affect anything else, it's just really annoying having to take my hand off the keyboard every time
If you run your code using cells (which allow you to break your file in sections by using comments of the form #%%) then you can go to
Preferences > Editor > Advanced settings > Maintain focus in the Editor after running cells or selections
and deactivate that option to get the behavior you want.
In R 3 * 2 typed on the editor can be executed in the console as [1] 6 by having the cursor on the line where the code is typed; clicking on Run if using RStudio, or through Ctrl + Enter. Very convenient.
New to Python, I am coming to realize the if I want to see 6, I may need to type print(3 * 2), unless I type the expression directly on the Python console. Or, is there a shortcut?
Incidentally, I am using Pycharm as IDE.
In the Pycharm charm editor go to
Settings > Keymap > Other
And change the kep map for "Execute selection in console". Double click it and select "Add keyboard shortcut"
I think the default is set the Alt+Shift+E. I was also from an R background before Pycharm and was used to the shortcut of Ctrl+R to run selected code. I think Ctrl+R might be something in Pycharm because I decided a long while back to map mine to Alt+R.
Once this is done, you can highlight a section and use your new shortcut to run it in a console. You can also just have a cursor on the line and using the shortcut will run the line and move to the next.
You need IPython. In particular, this ability to select a section of a saved file and re-execute it with a click or keypress is the hallmark of the Jupyter interface (previously known as "IPython Notebook").
If you have a script open in the Windows version of R, you can run a line (or section of highlighted code) in the shell by hitting CTRL-R (believe it's command-enter in apple version). Is there similar functionality for IDLE? Many thanks
No
In the shortcut key list in IDLE, in Options > Configure IDLE > Keys, in the Action - Key(s) list, one does not find any shortcut key for executing selected code.
IDLE with IdleX supports the ability to run a single line of code or a selection by pressing F9. It also has subCodes which allows you to run code in between '##' comments. It has the same effect as highlighting a lot of code for execution, but you don't need to keep highlighting each time.
If you type part of your search string before hitting Alt+P, then Alt+P will find only items starting with what you typed.
Pasting here from my own answer at https://stackoverflow.com/a/27702886/492336