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

Alexandre Vassalotti alexandre at peadrop.com
Fri Jul 20 18:21:56 CEST 2007


How this different from setting the position to the new size? What
should happen when someone call truncate() with an argument greater
than the current size? Should it do a seek, or nothing?

Thanks,
-- Alexandre

On 7/18/07, Guido van Rossum <guido at python.org> wrote:
> Unless anyone cares, it should imply a seek to the indicated position
> if an argument was present.
>
> On 7/18/07, Alexandre Vassalotti <alexandre at peadrop.com> wrote:
> > So, any decision on the proposed semantic change of truncate?
> >
> > On 7/3/07, Alexandre Vassalotti <alexandre at peadrop.com> wrote:
> > > On 7/2/07, Guido van Rossum <guido at python.org> wrote:
> > > > Honestly, I think truncate() should always set the current position to
> > > > the new size, even though that's not what it currently does.
> > >
> > > Thought about that and I think that would be the best thing to do.
> > > That would avoid making StringIO unnecessary different from BytesIO.
> > > And IMHO, it is less prone to bugs. If someone wants to truncate while
> > > keeping the current position, then he will have to state is intention
> > > explicitly by saving the value of tell() and calling seek() after
> > > truncating.
> > >
> > > I also find the semantic make more sense too. For example:
> > >
> > >    >>> s = StringIO("Good bye, world")
> > >    >>> s.truncate(10)
> > >    >>> s.write("cruel world")
> > >    >>> s.getvalue()
> > >    ???
> > >
> > > I think that should return "Good bye, cruel world", not "cruel world".
> > >
> > > So, does anyone else agree with this small semantic change of truncate()?
> > >


More information about the Python-3000 mailing list