Message56877
| 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:44 | christian.heimes | set | spambayes_score: 0.0673758 -> 0.06737577 recipients: + christian.heimes |
| 2007-10-28 11:09:43 | christian.heimes | set | spambayes_score: 0.0673758 -> 0.0673758 messageid: <1193569783.49.0.578170746692.issue1351@psf.upfronthosting.co.za> |
| 2007-10-28 11:09:43 | christian.heimes | link | issue1351 messages |
| 2007-10-28 11:09:42 | christian.heimes | create | |