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 benjamin.peterson
Recipients benjamin.peterson, esrever_otua
Date 2008-04-11.02:58:38
SpamBayes Score 0.10753698
Marked as misclassified No
Message-id <1207882720.12.0.757183393948.issue2612@psf.upfronthosting.co.za>
In-reply-to
Content
This is because y is a new-style class (because file is) and z is not.
If the return type of new-style classe's len is not an int, Python tries
to convert it, which is why that works for the first example. However,
that conversion doesn't happen in old-style classes. Try:

>>> class z(object):
...     def __init__(self, name):
...         self.f = file(name, 'r')
...     def __len__(self):
...         self.f.seek(0, 2)
...         return self.f.tell()
>>> x = z('/tmp/longfile')
>>> len(x)
[Whatever it is]
History
Date User Action Args
2008-04-11 02:58:40benjamin.petersonsetspambayes_score: 0.107537 -> 0.10753698
recipients: + benjamin.peterson, esrever_otua
2008-04-11 02:58:40benjamin.petersonsetspambayes_score: 0.107537 -> 0.107537
messageid: <1207882720.12.0.757183393948.issue2612@psf.upfronthosting.co.za>
2008-04-11 02:58:39benjamin.petersonlinkissue2612 messages
2008-04-11 02:58:38benjamin.petersoncreate