1、读文件
import os;
import time;
"""
读取二进制文件(比如图片等)
upfile需要读取的文件路径
"""
dir1="/Downloads/f5feff5f6597c51a1c8d15be36b08f79.jpeg"
def readbF(upfile):
f_name=os.path.basename(upfile)
#获取文件后缀
f_arr=f_name.split(".")
f_post_fix=f_arr[1]
print(f_post_fix)
#读取文件
with open(upfile,"rb") as fp:
file1=fp.readlines()
#获取时间戳
time_stamp=str(int(time.time()))
#读取的重命名文件名称
file_full="lara"+time_stamp+"."+f_post_fix
return file_full,file1
2、写文件
"""
写入二进制文件(比如图片等)
filename写入的文件名称
content写入的行内容
"""
def writeF(filename,content):
with open(filename,"wb") as fp:
fp.writelines(content)
writeF(file_name,file_content)