import os
bufsize = 1 << 15
with open('file.in', 'rb') as f, open('file.out', 'wb') as fout:
f.seek(0, os.SEEK_END) # move to the end of file
for pos in reversed(xrange(0, f.tell(), bufsize)):
f.seek(pos, os.SEEK_SET)
fout.write(f.read(bufsize)[::-1])
又快又脏的小曲:
不过,最好只反转
strings
的输出。在如果这些文件不是太大(即它们适合RAM),可以执行以下操作:
或者更安全:
^{pr2}$按相反顺序写入字节:
相关问题 更多 >
编程相关推荐