[Python-ideas] parameter omit

Aaron Brady castironpi at comcast.net
Fri May 11 01:14:11 CEST 2007


> -----Original Message-----
> From: Aaron Brady [mailto:castironpi at comcast.net]
> Sent: Wednesday, May 09, 2007 5:35 PM
> 
> Could easily incorporate, as shown here.
> #sample function with default args
> def f( a,b=None,c='abc' ):
>    print a,b,c
> 
> #customizer
> default= object()
> def call_wrapper( callable, *args, **kwargs ):
>    args=list(args)
>    for i,j in enumerate( args ):
>       if j is default:
>          offset= callable.func_code.co_argcount-\
>             len(callable.func_defaults)
>          args[i]= callable.func_defaults[i-offset]
>    return callable( *args,**kwargs )
> 
> #the uniform calls
> call_wrapper( f,0,default,'def' )
> call_wrapper( f,0,'somebody',default )
> 
> -----Original Message-----
> From: Aaron Brady [mailto:castironpi at comcast.net]
> Sent: Wednesday, May 09, 2007 4:56 PM
> To: 'Aaron Brady'; 'Josiah Carlson'; 'python-ideas at python.org'
> Subject: RE: [Python-ideas] parameter omit
> 
> You can almost do,
> 	b=f.func_defaults[1],
> but you still have to know where the defaults start.  Very small what I'm
> missing.
> 
> -----Original Message-----
> From: python-ideas-bounces at python.org
> [mailto:python-ideas-bounces at python.org] On Behalf Of Aaron Brady
> Sent: Wednesday, May 09, 2007 4:50 PM
> To: 'Josiah Carlson'; python-ideas at python.org
> Subject: Re: [Python-ideas] parameter omit
> 
> No, still not uniform.  Cases might be rare, even syntactic sugar maybe.
> if something huge:
> 	b=<def>
> more huge
> if something else:
> 	b=mything
> still more
> f(a,b,c).
> 
> -----Original Message-----
> From: Josiah Carlson [mailto:jcarlson at uci.edu]
> Sent: Wednesday, May 09, 2007 4:51 PM
> To: Aaron Brady; python-ideas at python.org
> Subject: Re: [Python-ideas] parameter omit
> 
> 
> "Aaron Brady" <castironpi at comcast.net> wrote:
> >
> > Actually, I wanted a uniform way to call f.  f(a,b,c) for both cases if
> b
> > can equal <def>.
> 
> f(a, b=...) #default c
> f(a, c=...) #default b
> 
> 
>  - Josiah
> 
> > -----Original Message-----
> > From: Steven Bethard [mailto:steven.bethard at gmail.com]
> > Sent: Wednesday, May 09, 2007 3:45 PM
> > To: Aaron Brady
> > Cc: python-ideas at python.org
> > Subject: Re: [Python-ideas] parameter omit
> >
> > On 5/9/07, Aaron Brady <castironpi at comcast.net> wrote:
> > > Is it possible to signal to a parameter to use its default?
> > >
> > > def f( a, b=None, c='' ):...
> > >
> > > f( 123, <def>, 'abc' )
> > > f( 123, ObjA, <def> )
> >
> > In this case, it's pretty easy::
> >
> >     f(123, c='abc')
> >     f(123, ObjA)
> >
> > 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

Also, any follow-up on this?  (I posted at top.)




More information about the Python-ideas mailing list