[Tutor] Passing values of a list as arguments
Andrew Wilkins
toodles@yifan.net
Fri, 23 Nov 2001 18:25:30 +0800
Hi Steve
*brings relevant part to top*
> ====================
> def somefunc(list)
> arg1, arg2 = list[1], list[2] or someOtherValue
Here you can use list-unpacking. As long as the length of the list is the
same as the amount of variables you are assigning to, you may use the
following:
arg1,arg2,...,argN = list
(though you probably shouldn't use the name "list", as it's a built-in)
HTH
Andrew
> Hi all,
> I just can't figure out to do this:
> ====================
> def somefunc(arg1, arg2=None)
> if not arg2:
> arg2 = someOtherValue
> ....
> ....
> ....
>
> if __name__ == '__main__':
> somefunc(sys.argv)
> ====================
> I hope you see my problem, I want to pass the values of sys.argv (or
any
> list for that matter) as arguments to somefunction, without resorting to
> something like:
> ....
> ....
> ....
>
> if __name__ == '__main__':
> somefunc(sys.argv)
> ====================
> ....which I think is kinda ugly for more that 3 arg values (python
sure
> does makes one *very* picky :))
>
> Peace
> Steve
> --
> ----------------------------------------------
> Every oak tree started out as a
> couple of nuts who stood their ground.
> Anonymous
> ----------------------------------------------
>
>
> _______________________________________________
> Tutor maillist - Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>