將照片以base64形式寫到檔案中
阿新 • • 發佈:2019-02-12
將目錄下每一個照片都寫成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)