[New-bugs-announce] [issue1351] Add getsize() to io instances

Christian Heimes report at bugs.python.org
Sun Oct 28 12:09:43 CET 2007


New submission from Christian Heimes:

I always missed a getsize() method on file objects. The patch adds a
method getsize() to all io instances. The method returns a SizeInfo
object which can print a human readable name or the bare size in bytes.
The method is using os.fstat and falls back to the seek(0,2), tell()
pattern.

>>> f = open("/etc/passwd")
>>> f.getsize()
<SizeInfo 1.7 KiB>
>>> int(f.getsize())
1721
>>> str(f.getsize())
'1.7 KiB'
>>> (f.getsize().sizeinfo())
(1.681, 1)

I'm going to provide unit tests and documentation if you like the feature.

----------
components: Library (Lib)
files: py3k_sizeinfo.patch
messages: 56877
nosy: tiran
severity: normal
status: open
title: Add getsize() to io instances
type: rfe
versions: Python 3.0
Added file: http://bugs.python.org/file8642/py3k_sizeinfo.patch

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1351>
__________________________________
-------------- next part --------------
A non-text attachment was scrubbed...
Name: py3k_sizeinfo.patch
Type: text/x-diff
Size: 2276 bytes
Desc: not available
Url : http://mail.python.org/pipermail/new-bugs-announce/attachments/20071028/e7543558/attachment.patch 


More information about the New-bugs-announce mailing list