哈希函数md5().hexdigest()

将文件保存时,通过哈希函数对每个文件进行文件名的自动生成。

 
 

import os

from hashlib import md5

def save_image(content):

file_path = '{0}/{1}.{2}'.format(os.getcwd(), md5(content).hexdigest(), 'jpg')#保存到当前路径,文件名自动哈希生成 print(file_path) if not os.path.exists(file_path): with open(file_path, 'wb') as f: f.write(content) f.close()

猜你喜欢

转载自blog.csdn.net/xiongzaiabc/article/details/80711899
今日推荐