I’m trying to copy file content from one file to another:
srcp = './output/name.jar'
dstp = './output/name'
os.remove(dstp)
src = open(srcp, 'r')
dst = open(dstp, 'w+b')
shutil.copyfileobj(src, dst)
src.close()
dst.close()
print os.path.getsize(srcp)
print os.path.getsize(dstp)
result is:
213815
3896
When I specify the length argument in shutil.copyfileobj copid size changes, but also wrong, cut constant for each length.
shutil.copyfile works fine, but I need to copy content because of my code copies another information before file content. In this test case I just trying to copy.
System: win 7 x32
You have disagreeing file modes.
You should use
'rb'for reading. Otherwise, line breaks are treated wrong, and 0x1A is recognized as EOF.