SyntaxError: multiple statements found while compiling a single statement

Steve D'Aprano steve+python at pearwood.info
Sat Oct 8 02:16:09 EDT 2016


On Sat, 8 Oct 2016 05:02 pm, Cai Gengyang wrote:

> Any idea how to correct this error ? Looks fine to me ....

As usual, the first and most important rule of debugging is to use ALL the
information the compiler gives you. Where is the rest of the traceback? At
the very least, even if nothing else, the compiler will print its best
guess at the failed line with a caret ^ pointing at the place it realised
there was an error.

Asking us to debug your problem without giving us ALL the information is
like that old joke:


  A man makes an appointment at the doctor because he isn't feeling
  well. He goes in to see the doctor, who says "So, Mr Smith, what 
  seems to be the problem?"

  The man says "You're the medical expert, you tell me."


I do not think it is possible to get the error message you claim from
running the code you show. I think there is more code that you haven't
shown us, and that the error is there.

The only way I can reproduce the error message you give is by using the
compile() function:

py> compile("a=1\nb=2", "", "single")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 1
    a=1
      ^
SyntaxError: multiple statements found while compiling a single statement


Notice how the compiler shows the offending line and puts a caret ^ at the
end?

Unless you show us what code actually causes this error message, I don't
think it is possible to help you. We're not mind-readers.





-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list