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
Related
Apologies in advance for what should seem obvious to me...
New to Python, but other wise very experience, hence the frustration.
As I'm learning, I'm attempting to prototype the command at the command prompt (">>>") as I script. I can enter the python commands and validate they are correct, but (currently) then have to retype the command in to sublime, which seems inane, especially as I'm watching videos where they are copying and pasting one to the other...
Windows 7 CMD, & Python ">>>" command lines, Sublime window
I'm trying to copy commands from the Python command line ">>>" to the sublime editor in an open/new tab. Normally, I would mark/highlight the selection, then Ctrl+c, place the cursor in the target window (sublime in this case), Ctrl-v, and be done.
However, I'm unable to select what I want to copy (??). Up/down arrows will recall the individual lines (no problem with that) -- where I would usually do a Ctrl-(left/right arrow) to select the text, but no indication that anything has been selected. Same result using the mouse.
Thanks in advance for the assist.
This is an oddity of the Windows command prompt. First, there is a little bit of setup. Then you can do the cut-and-paste in a slightly different way than you are used to.
Setup
Right click on the title bar at the top. Select "Properties". Click on the "Options" tab. Make sure that the "QuickEditMode" box is checked. Close the Properties window.
Cut-and-paste should be enabled, but not using control-C to cut. Select the text you want to copy. Instead of typing control-C, just hit return (with the desired text selected). The text should now be on the clipboard to paste into other applications (with control-V)
In Linux terminals, pressing Ctrl+k copies everything in the line that follows the cursor. Ctrl+u copies the everything before the cursor.
this is a very basic question, but is there a way to put '#' next to a highlighted bunch of code in psychopy for mac?
Edit: if you are using psychopy for mac you can press ctrl-' to input, ctrl-shift-' to remove.
Like the comments said, this is an editor issue and not a Python programming question. The closest thing there is to a "standard Python editor" is probably the one built into Idle, the IDE that comes with every CPython distribution. There, you can
Highlight the lines you want to comment out
Use Format>Comment Out Region from the menu or press Alt+4 at a PC keyboard.
This works in the module editor, not the shell, and uses a double pound sign as a hint that the lines were commented-out in a block operation.
Any editor with regular expression search and replacement and also with a "replace all within selection" option will work, too. Just highlight the lines and change all occurrences of ^ to # within that selection.
I'm doing a script with a menu-like beginning , and I wanted to know if I could do something like this:
You open the file and it prints this menu :
LOGO
Welcome to script 11 , what would you like to do?
-write a file
-read a file
-create a file
> #input here
You select write ( for example) and it prints this OVER the previous menu intead of printing if after it:
LOGO
Writing a file!
-Select the path:
> #input here
Thanks for the help in advance.
Edit: I didn't want to completely erase the screen( I've seen the other threads about that) but if there is a method to erase only some lines , but the anwers tell me that it isn't possible without external libraries so I'll just clean all the screen and reprint some things, but thanks for all the anwsers
If you are using Linux (or OSX), you can use the curses module.
If you are using windows, use the console module.
If you want to display a multi-line menu, and display an entirely new one after each menu choice, there are only a few ways to do this:
Clear the screen before printing each menu. There are about 69102 questions on SO about how to do this; how to clear the screen in python has links to many of them.
Print out a form feed/page feed. Which will not work on many modern terminals (Windows or Unix), but it rocks on old-school teletypes.
Use terminal control sequences to move the cursor around. This will work on Windows if the cmd terminal is ANSI-enabled (I believe it usually isn't by default), and on everything else if you pick (or look up) the right terminal to send control sequences for. You will also have to make sure to overwrite each character, not just each line. Otherwise, when you overwrite line 2 you'll end up with "Writing a file!pt 11 , what would you like to do?".
Use curses (and your favorite third-party Windows curses port), or some other terminal graphics library, to do this all at a higher level. (Writing separate code using console if it exists—for Windows—and curses otherwise—for almost everything else—is often the simplest way to do this.)
I'd suggest 1 or 4, but those are your options.
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
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.