There appears to be a bug in code.py in Python 3.0a2/a1.
I believe that the body of
InteractiveConsole().raw_input()
should be changed from
sys.stdout.write(prompt)
sys.stdout.flush()
return sys.stdin.readline()
to
return input(prompt)
Here's a sample session.
Python 3.0a1 (py3k, Nov 27 2007, 07:40:26)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import code
>>> console = code.InteractiveConsole()
>>> console.interact()
Python 3.0a1 (py3k, Nov 27 2007, 07:40:26)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> for i in range(3):
... print(i)
0
1
2
>>> # Notice how I could only enter one line inside the loop.
>>> # Let's try again, with a different definition of raw_input()
>>> import code
>>> console = code.InteractiveConsole()
>>> console.raw_input = input
>>> console.interact()
Python 3.0a1 (py3k, Nov 27 2007, 07:40:26)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> for i in range(3):
... print(i)
...
0
1
2
>>> # Notice how I had to enter an empty line to end the loop - as it
should be.
The same problem affects function definitions - it is impossible to
define a function body with more than one line when running code.interact()
|