io.BytesIO

Steven D'Aprano steve+comp.lang.python at pearwood.info
Mon Mar 25 02:54:07 EDT 2013


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.



-- 
Steven



More information about the Python-list mailing list