Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #33086
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2012-11-10 05:15 -0800 |
| References | <18134e77-9b02-4aec-afb0-794ed900d194@googlegroups.com> <roy-209335.20052609112012@news.panix.com> <509daadc$0$29980$c3e8da3$5496439d@news.astraweb.com> |
| Message-ID | <8e17124b-63ee-4166-8964-80f47f5716d5@googlegroups.com> (permalink) |
| Subject | Re: Is there a simpler way to modify all arguments in a function before using the arguments? |
| From | bruceg113355@gmail.com |
On Friday, November 9, 2012 8:16:12 PM UTC-5, Steven D'Aprano wrote:
> On Fri, 09 Nov 2012 20:05:26 -0500, Roy Smith wrote:
>
>
>
> > In article <18134e77-9b02-4aec-afb0-794ed900d194@googlegroups.com>,
>
> > bruceg113355@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.
>
>
>
>
>
> I agree with everything you say except that it is pretty weird. As far as
>
> I am concerned, it isn't weird at all.
>
>
>
> If you need named parameters:
>
>
>
> def someComputation(aa, bb, cc, dd, ee, ff, gg, hh):
>
> aa, bb, cc, dd, ee, ff, gg, hh = [arg.replace("_", "")
>
> for arg in (aa. bb, cc, dd, ee, ff, gg, hh)]
>
> ...
>
>
>
>
>
>
>
> --
>
> Steven
Thanks to all.
Steve's example is the one I will try next week.
Passing in lists, will work but it requires extra coding from the calling routines to build the list.
Discrete arguments make sense.
Also, what is the problem passing in 7 or more arguments?
Thanks,
Bruce
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Is there a simpler way to modify all arguments in a function before using the arguments? bruceg113355@gmail.com - 2012-11-09 16:48 -0800
Re: Is there a simpler way to modify all arguments in a function before using the arguments? Roy Smith <roy@panix.com> - 2012-11-09 20:05 -0500
Re: Is there a simpler way to modify all arguments in a function before using the arguments? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-10 01:16 +0000
Re: Is there a simpler way to modify all arguments in a function before using the arguments? bruceg113355@gmail.com - 2012-11-10 05:15 -0800
Re: Is there a simpler way to modify all arguments in a function before using the arguments? Chris Angelico <rosuav@gmail.com> - 2012-11-11 05:33 +1100
Re: Is there a simpler way to modify all arguments in a function before using the arguments? Paul Rubin <no.email@nospam.invalid> - 2012-11-09 18:52 -0800
Re: Is there a simpler way to modify all arguments in a function before using the arguments? Chris Angelico <rosuav@gmail.com> - 2012-11-10 14:56 +1100
Re: Is there a simpler way to modify all arguments in a function before using the arguments? Paul Rubin <no.email@nospam.invalid> - 2012-11-09 20:05 -0800
Re: Is there a simpler way to modify all arguments in a function before using the arguments? Chris Angelico <rosuav@gmail.com> - 2012-11-10 20:19 +1100
Re: Is there a simpler way to modify all arguments in a function before using the arguments? Miki Tebeka <miki.tebeka@gmail.com> - 2012-11-09 20:17 -0800
Re: Is there a simpler way to modify all arguments in a function before using the arguments? Peter Otten <__peter__@web.de> - 2012-11-10 10:09 +0100
Re: Is there a simpler way to modify all arguments in a function before using the arguments? aahz@pythoncraft.com (Aahz) - 2012-11-10 07:35 -0800
Re: Is there a simpler way to modify all arguments in a function before using the arguments? bruceg113355@gmail.com - 2012-11-10 09:56 -0800
Re: Is there a simpler way to modify all arguments in a function before using the arguments? Peter Otten <__peter__@web.de> - 2012-11-11 10:28 +0100
Re: Is there a simpler way to modify all arguments in a function before using the arguments? brucegoodstein@gmail.com - 2012-11-15 15:20 -0800
Re: Is there a simpler way to modify all arguments in a function before using the arguments? Emile van Sebille <emile@fenx.com> - 2012-11-15 16:03 -0800
Re: Is there a simpler way to modify all arguments in a function before using the arguments? Ethan Furman <ethan@stoneleaf.us> - 2012-11-15 20:00 -0800
Re: Is there a simpler way to modify all arguments in a function before using the arguments? bruceg113355@gmail.com - 2012-11-16 07:00 -0800
Re: Is there a simpler way to modify all arguments in a function before using the arguments? Ethan Furman <ethan@stoneleaf.us> - 2012-11-16 13:30 -0800
Re: Is there a simpler way to modify all arguments in a function before using the arguments? bruceg113355@gmail.com - 2012-11-16 07:00 -0800
Re: Is there a simpler way to modify all arguments in a function before using the arguments? Steve Howell <showell30@yahoo.com> - 2012-11-11 09:45 -0800
csiph-web