写个复制图片的python脚本:
1、下载一张图片到项目的根目录
2、读取该图片里的所有文件内容存放到一个全新的图片文件里面
#第一种
a = open('2.jpeg','rb')
b = open('3.jpeg','wb')
data = a.read()
b.write(data)
a.close()
b.close()
#第二种
src_file = '3.jpeg'
dst_file = '7.jpeg'
a = open(src_file,'rb')
b = open(dst_file,'wb')
while 1:
data = a.read(4096)
if data == b'':
break
b.write(data)
a.close()
b.close()
#第三种
src_file = '3.jpeg'
dst_file = '8.jpeg'
with open(src_file,'rb') as a:
with open(dst_file,'wb') as b:
while 1:
data = a.read(4096)
if data == b'':
break
b.write(data)
#第四种
src_file = '3.jpeg'
dst_file = '9.jpeg'
with open(src_file,'rb') as a:
with open(dst_file,'wb') as b:
while 1:
data = a.read(4096)
if len(data) == 0:
break
b.write(data)
#第五种
src_file = '3.jpeg'
dst_file = '10.jpeg'
with open(src_file,'rb') as a:
with open(dst_file,'wb') as b:
while 1:
data = a.read(4096)
if not data:
break
b.write(data)