我是python的新手,但正在尝试创建电话目录。每当我运行代码时,都会出现以下错误:
NameError:名称“ row”未定义
有什么办法解决这个问题吗?
import csv
rows = [['1', '2', '3', '4', '5', '6', '7'], ['8', '9', '10', '11', '12', '13', '14']]
with open('CSPBCcontacts.csv', 'w+', newline='') as csv_file:
writer = csv.writer(csv_file)
for row in rows:
writer.writerow(row)
with open ('CSPBCcontacts.csv', 'rt', newline='') as csv_file:
reader = csv.reader(csv_file)
for row in reader:
print(str(row))