Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #41846

Re: io.BytesIO

From Fabian von Romberg <fromberg100@hotmail.com>
Subject Re: io.BytesIO
Date 2013-03-25 21:43 -0500
References <mailman.3688.1364183789.2939.python-list@python.org> <514fd6d3$0$29998$c3e8da3$5496439d@news.astraweb.com> <mailman.3689.1364188221.2939.python-list@python.org> <514ff48f$0$29998$c3e8da3$5496439d@news.astraweb.com>
Newsgroups comp.lang.python
Message-ID <mailman.3711.1364265820.2939.python-list@python.org> (permalink)

Show all headers | View raw


Hi Steve,

thanks for your reply.

Actually I played around with these methods.  Whe you truncate(12468) for example, I thought the object would allocate 12468 bytes and I wanted to get that back.  The methods your mention, works only for what ha been written (obj.write()).

I think I should use io.BufferedWriter instead.

Just one question, what has better performance: BufferedWriter or BytesIO?

Thanks and regards,
Fabian

On 03/25/2013 01:54 AM, Steven D'Aprano wrote:
> On Mon, 25 Mar 2013 00:10:04 -0500, Fabian von Romberg wrote:
> 
>> Hi Steven,
>>
>>
>> actually why I need is to know how much memory has been allocated for
>> buffering.
>>
>> getsizeof gets the size of the object structure.
> 
> I can see at least four ways to get the current size of the BytesIO 
> buffer:
> 
> py> obj = io.BytesIO(b"x"*12468)
> py> obj.getbuffer().nbytes
> 12468
> py> len(obj.getvalue())
> 12468
> py> len(obj.getbuffer())
> 12468
> py> obj.seek(0, 2)
> 12468
> 
> 
> As far as I can tell, BytesIO objects do not have a fixed size buffer. 
> They will increase in size as needed, just like real file objects on a 
> disk.
> 
> 
> 

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

io.BytesIO Fabian von Romberg <fromberg100@hotmail.com> - 2013-03-24 22:56 -0500
  Re: io.BytesIO Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-25 04:47 +0000
    Re: io.BytesIO Fabian von Romberg <fromberg100@hotmail.com> - 2013-03-25 00:10 -0500
      Re: io.BytesIO Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-25 06:54 +0000
        Re: io.BytesIO Fabian von Romberg <fromberg100@hotmail.com> - 2013-03-25 21:43 -0500

csiph-web