How do I unindent using IDLE (Python gui)
I want to write the following statment in IDLE (Python GUI)
>>> if x == 0: ... x = 0 ... print('Negative changed to zero') ... elif x == 0:
How can I get the unindention for the elif statment ?
Some additional facts:
- I tried backspace and shift + tab, that doesn't help.
- Runing on Windows.
Thanks.
Sorry, you should just use backspace, thing is that ">>>" does not intent on indentation. That means that in:
>>> if x == 54: x = 4 elif y = 4: y = 6
elif is just as indented as the if statment.
Sorry to waste 开发者_如何学编程your time..., although you can blame the IDE for making an un-selfexplanitory UI.
Ctrl+[ should do the trick for unindenting.
Conversely, you can indent with Ctrl+], but IDLE generally handles indenting much better than unindenting.
ctrl + [
in Windows
command + [
in Mac
Backspace works for me.
If you go to Options->Configure IDLE and click on the Keys tab, what options are selected? It might make a difference - I have IDLE Classic Windows.
Try typing it like this. You'll notice the cursor moves to the start of the line after the pass
>>> if x == 0:
x = 0
print('Negative changed to zero')
pass
elif x == 0:
print('other stuff')
If, as you say, you're on Windows, you ought to check out the interactive IDE that comes with Mark Hammond's PyWin32
. It's available for all versions of Python including 2.6 and 3.1
It has user settable syntax coloring, code completion, automatic indent/dedent, and all the other features of IDLE while being generally slicker, faster and smoother operating and scrolling, etc. It also has a built-in debugger, although I don't use it enough to recommend it.
In addition it makes interactive input of compound statements more like the Python command line window in that it puts three dots (or more precisely, the value of sys.ps2
) in front of continuiation lines:
>>> if x < 0:
... x = 0
... print('Negative changed to zero')
... elif:
The tab key inserts the recommended 4 spaces (user configurable) and backspace will backup and delete 4 spaces so it looks like real tabs.
I've used PyWin32 since Python version 1.5 and can't praise it highly enough.
精彩评论