我这样做了但是我收到了一个错误 - '作家没有被定义'。
import csv
x = {1,2,3}
file = open('xyz.csv', 'w')
write = csv.writer(file)
for i in x:
writer.writerow((i,3))
file.close()
答案 0 :(得分:0)
您从未定义过writer
。您说write = csv.writer(file)
,请考虑将其更改为writer = csv.writer(file)
。
您的代码将是:
import csv
x = {1,2,3}
file = open('xyz.csv', 'w')
writer = csv.writer(file)
for i in x:
writer.writerow((i,3))
file.close()