tags:

views:

102

answers:

5

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.

A: 

ctrl+[ should do the trick.

chaos95
don't know why it was downvoted, works fine on windows. I guess it's probably option-] on mac or something,
CrazyJugglerDrummer
A: 

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')
gnibbler
Can I just get it to work without the pass?
Haim Bender
+1  A: 

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
A: 

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.

Haim Bender
This is not an answer. Please update your question with additional information. This is not a "discussion forum". You post (and update) your question. These are answers, not clarifications or conversations. Please delete this, and put these facts into your question.
S.Lott
A: 

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