Absolute seeking on a StringIO treats the offset as a character count regardless of the contents, so given that there is no "pretend it's UTF-8 and advance a given number of 'bytes'" machinery anyway, there's no reason not to allow seeking relative to the current location or the end of the 'file'. The error message is also misleading: "Can't do nonzero cur-relative seeks" even when the seek is relative to the end.
Sounds like you should just submit a bug report (and a PR with a fix if you
feel up to it). Since a relative seek to position p is typically just
implemented as an absolute seek to position f.tell()+p, this looks like an
odd omission, and I can't remember a reason for it. Looking at the code,
the fix looks pretty easy -- update _io_StringIO_seek_impl() in
Modules/_io/stringio.c.
On Thu, Jan 16, 2020 at 7:19 PM Random832
Absolute seeking on a StringIO treats the offset as a character count regardless of the contents, so given that there is no "pretend it's UTF-8 and advance a given number of 'bytes'" machinery anyway, there's no reason not to allow seeking relative to the current location or the end of the 'file'. The error message is also misleading: "Can't do nonzero cur-relative seeks" even when the seek is relative to the end. _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/SR5XTK... Code of Conduct: http://python.org/psf/codeofconduct/
-- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-c...
On Thu, Jan 16, 2020, at 23:07, Guido van Rossum wrote:
Sounds like you should just submit a bug report (and a PR with a fix if you feel up to it). Since a relative seek to position p is typically just implemented as an absolute seek to position f.tell()+p, this looks like an odd omission, and I can't remember a reason for it. Looking at the code, the fix looks pretty easy -- update _io_StringIO_seek_impl() in Modules/_io/stringio.c.
I guess my instinct was to post here first in case there was (or in case someone thought there was) a reason, since it's certainly something that's being specifically disallowed in the code rather than a consequence of something that's not checked properly. Submitted as issue 39365.
participants (2)
-
Guido van Rossum
-
Random832