[Python-3000] StringIO/BytesIO in io.py doesn't over-seek properly (original) (raw)

Guido van Rossum guido at python.org
Mon Jul 2 20:38:54 CEST 2007


Honestly, I think truncate() should always set the current position to the new size, even though that's not what it currently does. Or at least it should set it to the new size if that's less than the current position. What's the rationale (apart from "Unix defined it so") why it currently leaves the position unchanged?

At least I think it's fine if StringIO does it this way. I think TextIOWrapper should also do it this way, as it has the same issue (writing null bytes is not defined for encoded files).

--Guido

On 7/2/07, Alexandre Vassalotti <alexandre at peadrop.com> wrote:

If StringIO is not allowed to over-seek, what should happen to the current file position when it is truncated?

>>> s = StringIO("Hello world!") >>> s.seek(0, 2) >>> s.truncate(2) >>> s.tell() ??? Truncating can either set the position to the new string size, or it leaves it alone. -- Alexandre


Python-3000 mailing list Python-3000 at python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/guido%40python.org

-- --Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-3000 mailing list