[Python-ideas] parameter omit

Steven Bethard steven.bethard at gmail.com
Fri May 11 09:11:01 CEST 2007


On 5/11/07, Aaron Brady <castironpi at comcast.net> wrote:
> > -----Original Message-----
> > From: Steven Bethard [mailto:steven.bethard at gmail.com]
> > Sent: Friday, May 11, 2007 1:50 AM
> >
> > On 5/11/07, Aaron Brady <castironpi at comcast.net> wrote:
> > > Take a shot at this one.
> > >
> > > class WebRetrieveElement:
> > >         def netretrieveOld( self ):
> > >                 if hasattr( self,'hook' ) and self.filename:
> > >                         urlretrieve( self.url, self.filename, self.hook
> > )
> > >                 elif hashook:
> > >                         urlretrieve( self.url, reporthook= self.hook )
> > >                 else:
> > >                         urlretrieve( self.url, self.filename )
> >
> > def netretrieve(self):
> >     kwargs = {}
> >     if self.filename:
> >         kwargs['filename'] = self.filename
> >     if hasattr(self, 'hook'):
> >         kwargs['reporthook'] = self.hook
> >     urlretrieve(self.url, **kwargs)
>
> Right.  That's the alternative, -as- I keep bringing up.
>
> Now let's compare, and judge if X is worth Y.
>
> My solution, 3 lines.  Yours, 6.

If you really care about lines and characters, you can write::

    k = {}
    if self.filename: k['filename'] = self.filename
    if hasattr(self, 'hook'): k['reporthook'] = self.hook
    urlretrieve(self.url, **k)

That's 4 lines, 132 characters, compared to your 3 lines, 133 characters.

But the fact that you're drawing the "lets count lines of code" card
suggests that there's no point discussing this any further.

Good luck with your proposal.

STeVe
-- 
I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a
tiny blip on the distant coast of sanity.
        --- Bucky Katt, Get Fuzzy



More information about the Python-ideas mailing list