import csv
exampleFile = open('C:\\Users\\del\\Desktop\\123.csv')
xr = csv.reader(exampleFile)
user = []
for x in xr:
if xr.line_num == 1:
continue
print(x)
user.append(x)
print(user)
print(user[0][0])
print(user[0][1])
print(user[0][2])
exampleFile.close()
执行结果;
['fa', '韩国', 'riben', 'mei', '中']
['中', '韩国', 'mei', 'riben', 'fa']
['韩国', 'mei', 'riben', '中', 'fa']
[['fa', '韩国', 'riben', 'mei', '中'], ['中', '韩国', 'mei', 'riben', 'fa'], ['韩国', 'mei', 'riben', '中', 'fa']]
fa
韩国
riben
=============================================================================================
import csv exampleFile = open('C:\\Users\\del\\Desktop\\123.csv','a',newline='') xr = csv.writer(exampleFile) xr.writerow({'中','mei','fa','riben','韩国'}) exampleFile.close()
如果您忘记了open()中的newline =''关键字参数,则CSV文件将以双倍行距显示。