Is there a simpler way to modify all arguments in a function before using the arguments?

Roy Smith roy at panix.com
Sat Nov 10 02:05:26 CET 2012


In article <18134e77-9b02-4aec-afb0-794ed900d194 at googlegroups.com>,
 bruceg113355 at gmail.com wrote:

> Is there a simpler way to modify all arguments in a function before using the 
> arguments?
> 
> For example, can the below code, in the modify arguments section be made into 
> a few statements?  
> 
>     def someComputation (aa, bb, cc, dd, ee, ff, gg, hh):
>        # modify arguments
>        # ----------------------
>         aa = aa.replace (³_² , ³²)
>         bb=  bb.replace (³_² , ³²)
>         cc = cc.replace (³_² , ³²)
>         dd = dd.replace (³_² , ³²)
>         ee = ee.replace (³_² , ³²)
>         ff = ff.replace (³_² , ³²)
>         gg = gg.replace (³_² , ³²) 
>         hh = hh.replace (³_² , ³²)
> 
>        # use the arguments
>        # -----------------
>        # Š

You could do something like (not error checked)...

def someComputation(*args):
    new_args = [arg.replace("_", "") for arg in args]
    aa, bb, cc, dd, ee, ff, gg, hh = new_args

but that's pretty weird.  I suspect you just want to pass a list instead 
of a bunch of discrete arguments.


More information about the Python-list mailing list