9

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.

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Haim Bender
  • 7,937
  • 10
  • 53
  • 55
  • 1
    What have you tried? Backspace? Shift-tab? What platform are you using? Mac OS X, Windows and some Linux boxes have different keyboards. When you clicked on the Help menu, what did you find there? – S.Lott Oct 22 '09 at 22:23
  • Question for you or any bystander: how do you get the ... for your continuation lines? I've never seen IDLE do that, nor can I find an option to turn it on. Yet I've seen it in a few Python postings. – Mark Ransom Oct 22 '09 at 23:16

5 Answers5

23

Ctrl+[ should do the trick for unindenting.

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

chaos95
  • 719
  • 3
  • 9
4

ctrl + [ in Windows

command + [ in Mac

rainy
  • 1,577
  • 1
  • 19
  • 27
  • This is the default key combo. You can also change key assignments in the options to use Shift-Tab or whatever you like: http://stackoverflow.com/a/790788/60422 – rakslice Jul 03 '16 at 21:27
2

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.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
1

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')
John La Rooy
  • 295,403
  • 53
  • 369
  • 502
0

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.

Don O'Donnell
  • 4,538
  • 3
  • 26
  • 27