[Tutor] a question in the Python Tutorial

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Mon Sep 6 02:56:08 CEST 2004



> there is a piece of code:
>
> >>> # This is a comment
> ... 2+2
> 4
>
> I copy them into the Python shell, but cannot run:
>
> >>> # This is a comment
> ... 2+2
> SyntaxError: invalid syntax

Hello!

This is strange.  I can't duplicate this problem.  What are the lines
right before and after the "SyntaxError: invalid syntax" error message?
It should point at the character where it gets mixed up.


For example, if I type:

###
>>> !blah!
###

then Python responds with this:

###
  File "<stdin>", line 1
    !blah!
    ^
SyntaxError: invalid syntax
###

Here, Python points at the misplaced exclamation mark with a '^' caret
symbol.


Here's another example of an error message:

###
>>> # This is a comment
...  2 + 2
  File "<stdin>", line 2
    2 + 2
    ^
SyntaxError: invalid syntax
###

This is an error because I put a single space right before the '2 + 2'.
So Python's not perfect when it points out where problems start, but it
tries.  *grin*


Can you try your example again?  See if you can get Python to point out
where it starts getting confused.


Good luck to you!



More information about the Tutor mailing list