把所有的图片二进制存储在csv里,便于使用
import base64
import os
import csv
def getCsv():
os.chdir("./picture")
# print(os.getcwd())
f=open('../result.csv','w', newline='') #指定newline,否则csv文件会产生空行
fWrite=csv.writer(f)
fWrite.writerow(['path','name','data'])
for root,dirs,files in os.walk(os.getcwd()):
for file in files:
path=os.path.join(root,file)
print(path)
fp=open(path,'rb')
data=base64.b64encode(fp.read())
fWrite.writerow([path,file,data])
fp.close()
f.close()
生成的csv: