This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2020年01月17日 04:23 by random832, last changed 2022年04月11日 14:59 by admin. This issue is now closed.
| Messages (4) | |||
|---|---|---|---|
| msg360158 - (view) | Author: (random832) | Date: 2020年01月17日 04:23 | |
Currently this fails with a (misleading in the case of SEEK_END) "Can't do nonzero cur-relative seeks" error, but there's no conceptual reason it shouldn't be possible. The offset should simply be taken as a character offset, without any pretense that the "file" represents bytes in some Unicode encoding. This is already done for SEEK_START and tell, and has not caused any problems. |
|||
| msg360256 - (view) | Author: sanket (sanketplus) | Date: 2020年01月19日 12:27 | |
can you provide more details? Python version and code/steps to reproduce. That'd be more helpful as it seems the methods are already implemented in latest version https://docs.python.org/3/library/io.html#io.TextIOBase.seek |
|||
| msg360284 - (view) | Author: (random832) | Date: 2020年01月20日 02:56 | |
That documentation isn't specific to StringIO, and in any case, the limitation in question isn't documented. The actual implementation is at https://github.com/python/cpython/blob/HEAD/Modules/_io/stringio.c#L484 But if examples would help, they're simple to come up with: >>> f = io.StringIO('t\xe9st') >>> f.seek(-1, io.SEEK_END) Traceback (most recent call last): File "<stdin>", line 1, in <module> OSError: Can't do nonzero cur-relative seeks >>> f.seek(2, io.SEEK_CUR) Traceback (most recent call last): File "<stdin>", line 1, in <module> OSError: Can't do nonzero cur-relative seeks # demonstration that SEEK_SET works treating all characters as one unit >>> f.seek(2, io.SEEK_SET) 2 >>> f.read() 'st' As far as I know this is the case in all currently maintained versions of Python 3, since the C-based unicode StringIO implementation was added in 2008. |
|||
| msg360297 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2020年01月20日 08:22 | |
This is a duplicate of issue25190. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:59:25 | admin | set | github: 83546 |
| 2020年01月20日 08:22:33 | serhiy.storchaka | set | status: open -> closed resolution: duplicate type: behavior -> enhancement stage: resolved versions: + Python 3.9 nosy: + serhiy.storchaka messages: + msg360297 components: + Library (Lib) superseder: Define StringIO seek offset as code point offset |
| 2020年01月20日 02:56:55 | random832 | set | messages: + msg360284 |
| 2020年01月19日 12:27:50 | sanketplus | set | nosy:
+ sanketplus messages: + msg360256 |
| 2020年01月17日 04:23:15 | random832 | create | |