"unlist" a list
Stefan Schukat
SSchukat at dspace.de
Thu Jan 17 04:49:05 EST 2002
Use the apply function:
>>> def foo(v1,v2,*args):
... print v1,v2,args
...
>>> options = ["a", "b", "c"]
>>> foo("v1","v2",options)
v1 v2 (['a', 'b', 'c'],)
>>> apply(foo, ("v1","v2") + tuple(options))
v1 v2 ('a', 'b', 'c')
>>>
Stefan
> -----Original Message-----
> From: Klaus Hoeppner [mailto:klaus.hoeppner at bigfoot.de]
> Sent: Thursday, January 17, 2002 10:32 AM
> To: python-list at python.org
> Subject: "unlist" a list
>
>
> Hi,
> maybe a silly question:
>
> I use a funktion that is defined as foo(v1,v2,*args), i.e. it is
> called as
> a = foo(v1,v2,opt1,opt2,opt3...)
> (in fact in my case foo is Tkinter.OptionMenu)
>
> Unfortunately, I have the optional arguments in list
> options = [opt1,opt2,opt3,...]
> and oviously foo(v1,v2,options) goes wrong since foo assumes that
> opt1 is the list options.
> So I would need something like a unlist-operator telling foo that
> the list is not the single first optional arguments but the members
> of the list are the optional arguments.
>
> Any idea?
>
> Regards
> Klaus
> --
> http://mail.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list