[Python-3000] StringIO/BytesIO in io.py doesn't over-seek properly (original) (raw)
Guido van Rossum guido at python.org
Fri Jul 20 18:51:08 CEST 2007
- Previous message: [Python-3000] StringIO/BytesIO in io.py doesn't over-seek properly
- Next message: [Python-3000] Announcing PEP 3136
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
They shouldn't, really, and I don't care too much about what happens in that case. It may depend on whether the I/O device honors seeks beyond EOF or not.
On 7/20/07, Alexandre Vassalotti <alexandre at peadrop.com> wrote:
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()? > > >
-- --Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-3000] StringIO/BytesIO in io.py doesn't over-seek properly
- Next message: [Python-3000] Announcing PEP 3136
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]