interator应返回字符串,而不是字节

时间:2016-03-03 19:28:24

标签: python-3.x

我在Stackoverflow上找到了以下代码。编码使表格成为“学生”,但没有填充任何内容。我收到以下错误:

“错误:迭代器应该返回字符串,而不是字节(你是否在文本模式下打开文件?)

以下是代码:

import csv
import sqlite3

# Create the database
connection = sqlite3.connect('attendance5.db')
cursor = connection.cursor()

# Create the table
cursor.execute ('DROP TABLE IF EXISTS student')
cursor.execute ('CREATE TABLE student (StuID REAL, LastName TEXT, FirstName TEXT, Grade REAL, Address TEXT, Phone TEXT, Parent TEXT)')
connection.commit()

# Load the CSV file into CSV reader
csvfile = open ('attendance.csv','rb')
creader = csv.reader(csvfile, delimiter=',', quotechar='|')

# Iterate through the CSV reader, inserting values into the database
for t in creader
   cursor.execute ('INSERT INTO student VALUES (?,?,?,?,?,?,?)'t)

# Close the csv file, commit changes, and close the connection
csvfile.close()
connection.commit()
connection.close()

它与创造者中的t有什么关系吗?

我做错了什么?它是creader t值吗?谢谢。

0 个答案:

没有答案