[Tutor] IDLE question
alan.gauld at blueyonder.co.uk
Wed Jun 30 15:51:24 EDT 2004
> I'm trying to enter
> >>>if D.has_key("b"):
> print "yes"
> print "no"
Why? It's not valid Python?! :-)
> in IDLE v1.0.3. by typing it in, line by line. lines 1 and 2 go OK,
> hitting "Enter" after "yes" causes the cursor to move to just under
> "p" of "print", as expected. If I use the Backspace key and the
> to line up and indent "else:"
But the else should not be indented, it lines up with the if.
However a bug(at least I think its a bug!) in IDLE means that
IDLE ignores the effect of the >>> proimpt and thinks the if is
actually at the left margin, so your code needs to look like this:
>>> if D.has_key("b"):
Which is what ISLE is trying to make you do but to a human it
doesn't look right...
> indentation level (<pyshell#10>, line 3)". Is there no way to get
> entered other than typing the 4 lines in a text editor and pasting
> all together into IDLE?
Well you can use IDLE as that text editor by using File->NEw to create
a new window....
But if you want to use the Pyhon prompt you are stuck with IDLEs weird
behaviour. Oddly the DOS prompt doesn't do this because it adds ... on
lines following the >>> to align everything properly!
If you want a >>> prompt with the color coding and other bells of IDLE
try the pyShell that comes with wxPython. It is now my preferred
Python interactive prompt...
More information about the Tutor