Returning a variable number of things...

R

r0g

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.
 
C

Chris Rebert

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.

Despite its name, tuple unpacking works with lists too.

Cheers,
Chris
 
R

r0g

Chris said:
Despite its name, tuple unpacking works with lists too.

Cheers,
Chris

Ah so it does! Thanks Chris! I'm losing count of all the reasons I have
to love this language :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,296
Messages
2,571,535
Members
48,281
Latest member
DaneLxa72

Latest Threads

Top