Using an interable in place of *args?

sdd daniels at
Fri Nov 21 18:22:59 CET 2003

Nick Vargish wrote:

... Is there a general method for calling a function that expects *args
> with an iterable instead (tuple or, even better, a list)? I can see
> how I could do something funky with exec, but I'd like to avoid that
> if possible.

I'm unsure of what you mean; if you explain why this doesn't solve
your problem, we'll go from there?:

I suspect you want something that can be used in the following way:
     obj = dstruct(...)

To put a little meat in, I'll have pack simply print its args:

class dstruct(object):
     def pack(self, *args):
         for element in args:
             print element

This works, now what is unlike what you want?

-Scott David Daniels
Scott.Daniels at Acm.Org

More information about the Python-list mailing list