Skip to content

Instantly share code, notes, and snippets.

@Roger8
Last active July 10, 2018 07:45
Show Gist options
  • Save Roger8/757c4cde640ee215f6f1e9857270938e to your computer and use it in GitHub Desktop.
Save Roger8/757c4cde640ee215f6f1e9857270938e to your computer and use it in GitHub Desktop.
csv_python 操作
import csv

rows = [('oVtUlk8861.jpg','1'), ('oVtUlk8861.jpg','1'),('oVtUlk8861.jpg','1')]
with open('tt1.csv', 'wb') as f:  # 这里用的 wb, 用w 会在每行下加空行
     wr = csv.writer(f,dialect='excel')
     wr.writerows(rows)

tt1.csv

oVtUlk8861.jpg,1
GUKTVcU056.jpg,1
37HJuoo706.jpg,1
@Roger8
Copy link
Author

Roger8 commented Jul 10, 2018

# 读取csv文件方式2
with open("csvData.csv", "r") as csvfile:
    reader2 = csv.reader(csvfile) # 读取csv文件,返回的是迭代类型
    for item2 in reader2:
        print(item2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment