[issue1351] Add getsize() to io instances

Christian Heimes report at bugs.python.org
Sun Oct 28 19:14:43 CET 2007


Christian Heimes added the comment:

Martin v. Löwis wrote:
> I'm skeptical:
> 
> - If you add getsize, why not getlastchangeddate, getowner, getpermissions?

getowner() etc. work only with file based streams and not with memory
buffers. getsize() works with every concrete class in io.py

> - in general, streams (which really is the interface for file-like
> objects) don't have the notion of "size"; only some do.

I understand that getsize() doesn't make sense for e.g. a socket based
stream. However the implementation of getsize() works with memory
buffers and file descriptors

> - what is the purpose of the f.tell fragment? ie. why could that work
> when fstat doesn't?

The tell(), seek(0,2) is a generic fall back for io instances that
aren't based on a file descriptor. It's required for BytesIO and
StringIO. However I could come up with an implementation for BytesIO
that queries the buffer directly.

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1351>
__________________________________


More information about the Python-bugs-list mailing list