【发布时间】:2014-08-29 18:57:03
【问题描述】:
这是一个错误吗?它演示了当您使用 libtiff 从打开的 tiff 文件句柄中提取图像时会发生什么。它适用于 python 2.x,不适用于 python 3.2.3
import os
# any file will work here, since it's not actually loading the tiff
# assuming it's big enough for the seek
filename = "/home/kostrom/git/wiredfool-pillow/Tests/images/multipage.tiff"
def test():
fp1 = open(filename, "rb")
buf1 = fp1.read(8)
fp1.seek(28)
fp1.read(2)
for x in range(16):
fp1.read(12)
fp1.read(4)
fd = os.dup(fp1.fileno())
os.lseek(fd, 28, os.SEEK_SET)
os.close(fd)
# this magically fixes it: fp1.tell()
fp1.seek(284)
expect_284 = fp1.tell()
print ("expected 284, actual %d" % expect_284)
test()
我觉得错误的输出是: 预期 284,实际 -504
取消注释 fp1.tell() 会产生一些......副作用......这会稳定 py3 句柄,我不知道为什么。如果有人可以测试其他版本的 python3,我也将不胜感激。
【问题讨论】:
-
您没有告诉我们发生的事情与您的预期不同。
标签: python file python-3.2