需求python读取一个二进制文件,然后写入另一个文件,在这里关键是判断文件长度的语句:os.path.getsize('file')
#!/usr/bin/env python
import os
f1 = open("wxPython4.jpg", "w")
#f1.write(data)
count = os.path.getsize('wxPython.jpg')
data = ""
f = open('wxPython.jpg', 'rb')
while count > 0:
if count < 1024:
data = f.read(count)
count = count - count
else:
data = f.read(1024)
count = count -1024
f1.write(data)
#if count == 0:
# break
f.close()
f1.close()