[Python-ideas] parameter omit

Aaron Brady castironpi at comcast.net
Fri May 11 08:28:59 CEST 2007


> -----Original Message-----
> From: python-ideas-bounces at python.org [mailto:python-ideas-
> bounces at python.org] On Behalf Of Aaron Brady
> Sent: Friday, May 11, 2007 12:23 AM
> 
> > -----Original Message-----
> > From: Steven Bethard [mailto:steven.bethard at gmail.com]
> > Sent: Friday, May 11, 2007 12:13 AM
> >
> > On 5/10/07, Aaron Brady <castironpi at comcast.net> wrote:
> > [snip]
> > > The new way:
> > >
> > > my_b, my_c= paramdefault, paramdefault
> > > [code to assign my_b and my_c]
> > > foo(a, my_b, my_c)
> >
> > As another poster mentioned, the normal way to write this is::
> >
> >     kwargs = {}
> >     if use_default_b:
> >         kwargs['b'] = my_b
> >     if use_default_c:
> >         kwargs['c'] = my_c
> >     foo(a, **kwargs)
> >
> > It is so extremely uncommon to need to do such a thing that I'm firmly
> > against adding any additional syntax. Syntax should only be introduced
> > for common things that many people need.
> >
> > STeVe

Steve,

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 netretrieveNew( self ):
		filename= self.filename or ParamDefault
		hook= hasattr( self,'hook' ) and self.hook or ParamDefault
		urlretrieve( self.url, filename, hook )

What is the default parameter for the function?  Problem is, the docs don't
say what it is.  Does it pick its own filename to use for empty inputs?






More information about the Python-ideas mailing list