【发布时间】:2012-10-26 08:12:04
【问题描述】:
执行以下代码时,在第二次读取后,文件会被零填充,直到 4096 字节大。我不知道为什么:
f = open("file.txt", "w+")
f.read()
# gives ''
f.write("Hello")
f.read()
# filled with \x00,\x00
f.close()
# file is 4096 bytes large...
【问题讨论】:
-
如何测量文件的大小?
-
-
我的机器上没有得到结果,你的平台是什么?
-
我认为你不能在
write()之后没有flush()之间的read()。 -
哪个操作系统?和 Marcus 一样,我无法在 Linux、x86-64 上重现它。
标签: python python-2.7