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. > > > -- http://mail.python.org/mailman/listinfo/python-list