file.seek() and file.tell() look inconsistent to me
Christian Heimes
christian at python.org
Mon Jul 4 16:45:34 EDT 2016
On 2016-07-04 17:48, Marco Buttu wrote:
> Hi all,
>
> if I open a file in text mode, do you know why file.seek() returns the
> number of bytes, and file.tell() takes the number of bytes? I was
> expecting the number of characters, like write() does:
Your expectations are not correct. tell() and seek() of a file in binary
mode return the current position of the file descriptor. For a file in
text mode, tell() and seek() use a opaque number [1]. The number
reflects the internal state of the text IO object. You can't draw any
conclusion from it. You are only allowed to seek to offsets which you
have acquired by tell(), too.
[1] https://docs.python.org/3/library/io.html#io.TextIOBase.tell
More information about the Python-list
mailing list