New submission from Darryl Dixon <[EMAIL PROTECTED]>:

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 <[EMAIL PROTECTED]>
<http://bugs.python.org/issue2612>
__________________________________
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to