Returning a variable number of things...

r0g aioe.org at technicalbloke.com
Fri Feb 6 19:50:05 CET 2009


Hi There,

I have a function that uses *args to accept a variable number of
parameters and I would like it to return a variable number of objects.

I could return a list but I would like to take advantage of tuple
unpacking with the return values e.g.

def unpack_struct( a_string, *args ):
  output_vars = []
  for each in *args:
    <<< build a list of output values >>>
  return <<< the tuple equivalent of this list >>>

ip, meat, zipcode = unpack_struct( "192.168.001.001Ham22132", 15, 3, 5 )

Thanks,


Roger.



More information about the Python-list mailing list