创建文件并想要创建数据库后出现主模块错误

时间:2019-04-10 04:06:35

标签: python mysql python-3.x raspberry-pi

我当前正在创建一个MySQL数据库,该数据库想使用for循环遍历包含表中值的数据字段。我已经成功完成了代码,但是当我想运行脚本以最终写入数据库时​​,会出现

错误
python3 blueteamcolorassignment9.py
/usr/bin/python3: can't find '__main__' module in 'blueteamcolorassignment9.py'

假设要从此for循环中接收值。

python3
Python 3.5.3 (default, Sep 27 2018, 17:25:39) 
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> #!/usr/bin/python3
... import mysql.connector
>>> conn = mysql.connector.connect(user='root',password='alozon23',database='pytest')
>>> cursor = conn.cursor()
>>> query = ('SELECT empid,lastname,firstname,salary FROM employees')
>>> cursor.execute(query)
>>> for (empid,lastname,firstname,salary) in cursor:
...  print(empid,lastname,firstname,salary)
... cursor.close()
  File "<stdin>", line 3
    cursor.close()
         ^
SyntaxError: invalid syntax
>>> cursor.close()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/mysql/connector/cursor.py", line 336, in close
    raise errors.InternalError("Unread result found.")
mysql.connector.errors.InternalError: Unread result found.
>>> conn.close()
>>> exit;
Use exit() or Ctrl-D (i.e. EOF) to exit
>>> exit()

0 个答案:

没有答案