overriding file.readline: "an integer is required"

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Tue Aug 5 04:24:42 EDT 2008


En Fri, 01 Aug 2008 16:21:26 -0300, kj <socyl at 987jk.com.invalid> escribi�:

> In <mailman.953.1217472439.922.python-list at python.org> Miles  
> <semanticist at gmail.com> writes:
>
>> On Wed, Jul 30, 2008 at 5:52 PM, kj <socyl at 987jk.com.invalid> wrote:
>>> I know that I could rewrite the method like this:
>>>
>>>    def readline(self, size=None):
>>>        if size == None:
>>>            line = self.file.readline()
>>>        else:
>>>            line = self.file.readline(size)
>>>        # etc., etc.
>>>
>>> ...but this seems to me exceptionally awkward.  (Actually, it's worse
>>> than awkward: it fails to complain when the overriding method is
>>> called with the argument None.
>
>> You could of course do:
>
>>    def readline(self, *args):
>>        line = self.file.readline(*args)
>>        # etc., etc.
>
>> But this has its drawbacks.
>
> Like what?  (I'm pretty new to Python and these drawbacks are not
> obvious to me.)

One thing I can think of: The help system (and the code autocompleter  
found in some editors, and other introspection tools) can't tell you the  
name/number/default value of the arguments anymore: they're all masked  
into a generic *args

-- 
Gabriel Genellina




More information about the Python-list mailing list