Using an interable in place of *args?

sdd daniels at dsl-only.net
Fri Nov 21 12:22:59 EST 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(...)
     ...
     obj.pack(5,4,3,2)

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