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
Related
Every time I use the help function in the python console, I have to scroll up and look for the exact place where the help text starts.
Is there a way to make the cursor jump directly to this position?
You press the letter g.
The bindings for the python help text can be found in the less command manual, in the COMMANDS section. You can access this manual by running man less in a shell if you're running Linux.
I want to shift back the entire code 1 tab backwards. Is that possible? What is the key commbination? I am using Idle 3.6.3 on an Mac OSX System.
Thanks for the help!
Whilst it's absolutely a question about your editor rather than Python, many editors actually use the same key combo for this. On my Mac, it's the same in VS-Code, Sublime3 and TextMate:
cmd-a to select all text (or select a smaller region if you prefer)
cmd-[ to un-indent the selected block one stop (and cmd-] to indent)
Here's a video I made demonstrating the process in TextMate on a MacBook Pro:
https://www.youtube.com/watch?v=vyHRi2xXAnA
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").
IDLE is being very dodgy as to when it will actually show an Auto-complete menu. As of late it hasn't been working at all, or, more specifically, only works during an interactive session.
I've been using Code Blocks for C, and have gotten really used to the very nice auto-complete features, so it's a bit frustrating not having them -- especially while trying to learn a new frame work and what class is associated with which methods, etc, etc..
Is there an easy fix to get IDLE auto-complete working again? I'm using python version 2.7.
Is there perhaps a simple editor I should look into? I've tried Vim, which was a little too heavy for my simple needs, Ninja, which I couldn't get to work for anything, and Sublime text 2, which I couldn't get my wxpython stuff to play with. What would a nice option be? Anything similar to Code Blocks would be cool, although, I'd be perfectly happy with IDLE if it would consistently work!
REQUESTED CLARIFICATION:
OK, so it seems I may have some of my terminology backwards. By non-interactive, I mean, for instance, right clicking on a python file and selecting "edit with IDLE". This brings up what I guess could be described as a text editor. You can enter all you code here. Once ready, you then hit F5, or select Run, and it launches (what I've been referring to as) the interactive terminal. It's here that you can type in code, press return, and instantly have that code evaluated.
What my question is referring to it the former, the part of IDLE where you edit the code. Sometimes while typing, after a . it will display the available methods, or after an open parenthesis it'll give hints as to the values expected. but the thing is, sometimes it does these things, sometimes it doesn't.
The only thing i found so far is that if an editing session of IDLE is connected with python shell (called "interactive mode" in the question, i.e. after an attempt to run the edited script) then "non-interactive" IDLE can autocomplete based on values in interactive window. For example, if I type
a = [];
a.appen
and then hit < Tab > it will do nothing, but if I previously type
a = []
in corresponding python shell, IDLE will autocomplete correctly.
So my only suggestion is import same modules with same names in python shell window in order to make them "visible" for non-interactive IDLE editor.
I had the same problem with IDLE, because I want to learn Qt and therefore autocompletion is very useful.
As it says in the settings of IDLE, you can trigger the autocomplete with "Control + Space", e.g. after a "QtGui.". Then a menu opens where you can arrow-scroll through the entries.
using the 'IDLE Editor window', you need to save and execute your code first.
The application running, turn back to the Editor window to use the auto-completion.
In my case, I had to open Options menu -> Extensions tab on the editor and look to make sure AutoComplete and other relevant options were enabled. They actually were, but by just clicking on 'Apply' even though I dint have to change anything did the trick for me.
Sometimes it has to do with the time you have to wait to get a suggestions.
When you go to options > extensions > general at completions popup wait you can change it to about 500ms.
In my case it was 2000ms by default.
hi everyone :)
my problem is, up until now, i have exclusively used tabs to indent python, as i find it easier than spaces, but for no reason i know, python interactive prompt, the basic python.exe one, suddenly refuses to accept the tab button, all it does is flash the cursor. all i can think of is that my computer in suddenly treading the window like any other, using tab to cycle input things, in this case the single one. also, before now, i could use the up button to reach previously typed code, the if i submit that line with no changes, use the down button to access the line that came after it, but now up works, but as if i had changed the line, eg moves me back to the "bottom" of the list of inputs, so down doesn't work.... my question simply is: how do i get my good old tab and down button to work like i want them to again? :(
thanks xxx
If you are using Windows with the standard cmd.exe console (and it would have been helpful for you to have stated this up front) then you can use the TAB and arrow keys exactly as you desire.
I recently observed this behavior too, on Windows, using cmd.exe. It also happens with Console2 - an alternate shell I sometimes use.
Though I do always use spaces in normal code in an editor, I had been accustomed to using the Tab key to indent in short multi-line inputs in the interactive python.exe interpreter. Recently that stopped working - pressing the Tab key flashes the cursor and doesn't indent. Using spaces does work fine here, though it's not as convenient past a couple of indentations.
I suspect (but am not certain) that the cause was installation of pyreadline or rlcompleter - I had been messing with trying to get tab completion in an interpreter in an embedded application on Windows. Of course in your case another installation could have included those packages.