This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author christian.heimes
Recipients christian.heimes
Date 2007-10-28.11:09:38
SpamBayes Score 0.06737577
Marked as misclassified No
Message-id <1193569783.49.0.578170746692.issue1351@psf.upfronthosting.co.za>
In-reply-to
Content
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.
Files
File name Uploaded
py3k_sizeinfo.patch christian.heimes, 2007-10-28.11:09:42
History
Date User Action Args
2007-10-28 11:09:44christian.heimessetspambayes_score: 0.0673758 -> 0.06737577
recipients: + christian.heimes
2007-10-28 11:09:43christian.heimessetspambayes_score: 0.0673758 -> 0.0673758
messageid: <1193569783.49.0.578170746692.issue1351@psf.upfronthosting.co.za>
2007-10-28 11:09:43christian.heimeslinkissue1351 messages
2007-10-28 11:09:42christian.heimescreate