On Sun, 8 May 2022 22:48:32 +0200, Marco Sulla <marco.sulla.pyt...@gmail.com> declaimed the following:
> >Emh. I re-quote > >seek(offset, whence=SEEK_SET) >Change the stream position to the given byte offset. > >And so on. No mention of differences between text and binary mode. You ignore that, underneath, Python is just wrapping the C API... And the documentation for C explicitly specifies that other then SEEK_END with offset 0, and SEEK_SET with offset of 0, for a text file one can only rely upon SEEK_SET using an offset previously obtained with (C) ftell() / (Python) .tell() . https://docs.python.org/3/library/io.html """ class io.IOBase The abstract base class for all I/O classes. """ seek(offset, whence=SEEK_SET) Change the stream position to the given byte offset. offset is interpreted relative to the position indicated by whence. The default value for whence is SEEK_SET. Values for whence are: """ Applicable to BINARY MODE I/O: For UTF-8 and any other multibyte encoding, this means you could end up positioning into the middle of a "character" and subsequently read garbage. It is on you to handle synchronizing on a valid character position, and also to handle different line ending conventions. """ class io.TextIOBase Base class for text streams. This class provides a character and line based interface to stream I/O. It inherits IOBase. """ seek(offset, whence=SEEK_SET) Change the stream position to the given offset. Behaviour depends on the whence parameter. The default value for whence is SEEK_SET. SEEK_SET or 0: seek from the start of the stream (the default); offset must either be a number returned by TextIOBase.tell(), or zero. Any other offset value produces undefined behaviour. SEEK_CUR or 1: “seek” to the current position; offset must be zero, which is a no-operation (all other values are unsupported). SEEK_END or 2: seek to the end of the stream; offset must be zero (all other values are unsupported). """ EMPHASIS: "offset must either be a number returned by TextIOBase.tell(), or zero." TEXT I/O, with a specified encoding, will return Unicode data points, and will handle converting line ending to the internal (<lf> represents new-line) format. Since your code does not specify BINARY mode in the open statement, Python should be using TEXT mode. -- Wulfraed Dennis Lee Bieber AF6VN wlfr...@ix.netcom.com http://wlfraed.microdiversity.freeddns.org/ -- https://mail.python.org/mailman/listinfo/python-list