I have a problem with the next code.
try: 1+1
except Exception as exception: pass
1+1
try: 2+2
except Exception as exception: pass
The result I get in the prompt is
... ... File "<stdin>", line 3
1+1
^
SyntaxError: invalid syntax
>>> ... ... ... 4
However the next code executes with no error.
try: 1+1
except Exception as exception: pass
try: 2+2
except Exception as exception: pass
My sys.version_info is:
sys.version_info(major=2, minor=7, micro=3, releaselevel='final', serial=0)
Why do I get the syntax error?
asked Feb 16, 2015 at 19:29
Usobi
1,8564 gold badges18 silver badges25 bronze badges
1 Answer 1
When using the interactive prompt, there needs to be a blank line between a block (such as a try/except block) and the next independent command. This is only in the REPL, when running a .py file it's not necessary.
answered Feb 16, 2015 at 19:32
MattDMo
103k21 gold badges251 silver badges239 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
MattDMo
@Usobi basically, when you're in the REPL and the prompt is
... instead of >>>, you're still inside a block.lang-py