[New-bugs-announce] [issue2612] file.tell() returns Long usually, Int if subclassed
Darryl Dixon
report at bugs.python.org
Fri Apr 11 04:45:15 CEST 2008
New submission from Darryl Dixon <esrever_otua at winterhouseconsulting.com>:
Compare:
>>> class y(file):
... def __init__(self, name):
... file.__init__(self, name)
... def __len__(self):
... self.seek(0, 2)
... return self.tell()
...
>>> n = y('/tmp/longfile')
>>> len(n)
364773376
Versus:
>>> class z:
... 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)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: __len__() should return an int
Because:
>>> x = file('/tmp/longfile')
>>> type(x.tell())
<type 'long'>
----------
components: Library (Lib)
messages: 65331
nosy: esrever_otua
severity: normal
status: open
title: file.tell() returns Long usually, Int if subclassed
type: behavior
versions: Python 2.4
__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2612>
__________________________________
More information about the New-bugs-announce
mailing list