将目录下每一个照片都写成base64的形式,并存到相应的文件中,接下来就上代码吧。
#coding=utf-8
import base64
import time
import os
def create_file(path):
ls = os.listdir(path)
for i in ls :
mulu=str(path)+str(i)
f=open(mulu,"rb") #以二进制形式打开
ls_f = base64.b64encode(f.read())
filename = "D:\\Python\\out"+str(i).split('.')[0]+".txt"
with open(filename, 'w') as file:
file.write(ls_f)
start=time.time()
path="D:\\Python\\"
create_file(path)
print('post time:',time.time()-start)
以上就是这些啦。