Haim Bender
Haim Bender

Reputation: 8187

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:

  1. I tried backspace and shift + tab, that doesn't help.
  2. 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.

Upvotes: 10

Views: 12123

Answers (5)

chaos95
chaos95

Reputation: 729

Ctrl+[ should do the trick for unindenting.

Conversely, you can indent with Ctrl+], but IDLE generally handles indenting much better than unindenting.

Upvotes: 24

rainy
rainy

Reputation: 1587

ctrl + [ in Windows

command + [ in Mac

Upvotes: 4

Don O'Donnell
Don O'Donnell

Reputation: 4728

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.

Upvotes: 0

Mark Ransom
Mark Ransom

Reputation: 308091

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.

Upvotes: 2

John La Rooy
John La Rooy

Reputation: 304117

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')

Upvotes: 1

Related Questions