python读写.csv格式文件

#win10 vscode 如果print输出中文乱码,请设置环境变量PYTHONIOENCODING=UTF8
#read csvfile
#import xlrd
#import xlwt
import csv
import numpy as np
filename='timu0.csv'
with open(filename) as f:
    r1 = csv.reader(f)
    #print(list(r1))
    for row in r1:
        print(r1.line_num,row,end="\n")
print("I love 我爱你!")
#写入csv数据write csv data to a file.
datas=[['商品编号', '商品名称', '单价', '库存', '销量'],
['1', '猫零食', '12', '3133', '5164'],
['2', '普通猫粮', '33', '5055', '2231'],
['3', '猫粮四合一', '187', '212', '334']]
with open('d:/python/file.csv',"w",newline='') as w:
    w1=csv.writer(w)
    for row in datas:
        w1.writerow(row)    #每次写入一行
    w1.writerows(datas)     #一次性把datas写入文件
#numpy savetxt()写入,loadtxt()读取csv文件
a=np.arange(20).reshape(5,4)
b=np.savetxt('txt_a.csv',a,fmt="%d",delimiter=",")
print(a)
a_array=np.loadtxt("txt_a.csv",dtype=str,delimiter=None)
print(a_array)