Can anyone tell me why the length of data is much less than the position of the end of the file? I would have expected these to be equal.
>>> target = open('target.jpg')
>>> print target.tell()
0
>>&g开发者_StackOverflow社区t; data = target.read()
>>> print target.tell()
40962
>>> print len(data)
52
Open the file in binary mode:
target = open('target.jpg','rb')
I would not trust tell() on a file not opened as binary.
Later: actually, on reviewing the comments, I should have said I would not trust a read
on a binary file opened as text.
精彩评论