[Tutor] Interactive only syntaxerror?

Bob Gailer bgailer at alum.rpi.edu
Sat Oct 30 15:09:47 CEST 2004


At 06:25 AM 10/30/2004, bob at nc.rr.com wrote:
>Given the following file - test.py:
>----------------------------------
>if 1:
>   print "True"
>print "Done"
>----------------------------------
>Invoking python at the command prompt works, as expected:
>----------------------------------
>C:\Python>python test.py
>True
>Done
>
>C:\Python>python <test.py
>True
>Done
>----------------------------------
>Why does this fail with a SyntaxError?
>----------------------------------
>C:\Python>python
>Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on win32
>Type "help", "copyright", "credits" or "license" for more information.
> >>> if 1:
>...   print "True"
>... print "Done"
>   File "<stdin>", line 3
>     print "Done"
>         ^
>SyntaxError: invalid syntax

The ... prompt is asking for an indented line of code as part of the if block
Hit enter at the 2nd ... to end the if block (which will then execute) and 
enter print "Done" at the following >>>
Should look like:

 >>> if 1:
...   print "True"
...
True
 >>> print "Done"
Done


Bob Gailer
bgailer at alum.rpi.edu
303 442 2625 home
720 938 2625 cell 



More information about the Tutor mailing list