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 <[EMAIL PROTECTED]> 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@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/) _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com