SyntaxError: multiple statements found while compiling a single statement

最后都变了- 提交于 2019-11-26 06:48:59

问题


I\'m in Python 3.3 and I\'m only entering these 3 lines:

import sklearn as sk
import numpy as np
import matplotlib.pyplot as plt

I\'m getting this error:

SyntaxError: multiple statements found while compiling a single statement

What could I be doing wrong?

Edit: If anyone comes across this question, the solution I found was to download Idlex and use its IDLE version, which allows multiple lines.

Screenshot: http://imgur.com/AJSrhhD


回答1:


In the shell, you can't execute more than one statement at a time:

>>> x = 5
y = 6
SyntaxError: multiple statements found while compiling a single statement

You need to execute them one by one:

>>> x = 5
>>> y = 6
>>>

When you see multiple statements are being declared, that means you're seeing a script, which will be executed later. But in the interactive interpreter, you can't do more than one statement at a time.




回答2:


yes, you can only do that BUT if you want to do more than once then you need to use a notepad type in your code and then save it as (your file name) and .py this says it is a python file, hope that helps!

(P.S i'm actually 10 years old doing an online MIT course the link for the course is here: https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/)



来源:https://stackoverflow.com/questions/21226808/syntaxerror-multiple-statements-found-while-compiling-a-single-statement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!