What do you want put into the "missing" variables? I'll assume None. Something like following works:
values=line.split(':') try: a=values.pop(0) except IndexError: a=None try: b=values.pop(0) except IndexError: b=None try: c=values.pop(0) except IndexError: c=None
Larry Bates
TB wrote:
Hi,
Is there an elegant way to assign to a list from a list of unknown size? For example, how could you do something like:
a, b, c = (line.split(':'))
if line could have less than three fields?
Thanks, TB
-- http://mail.python.org/mailman/listinfo/python-list