Using an interable in place of *args?

Evan Simpson evan at 4-am.com
Fri Nov 21 11:47:32 EST 2003


Nick Vargish wrote:
>     def pack(self):
>         # need some way to call struct.pack with a list/tuple of values
>         # built with [ self.__dict__[v] for v in self.fields ]
>         pass

Shouldn't this work?

   struct.pack(*tuple([ self.__dict__[v] for v in self.fields ]))

Cheers,

Evan







More information about the Python-list mailing list