1、format()

在保存图片时,路径可以写成这样:

import os
from hashlib import md5

def save_image(content):
    file_path = '{0}/{1}.{2}'.format(os.getcwd(),md5(content).hexdigest(),'jpg')
    if not os.path.exists(file_path):
        with open(file_path,'wb') as f:
            f.write(content)
            f.close()

 

posted on 2017-07-28 11:13  漏三刀  阅读(132)  评论(0编辑  收藏  举报