default value in a list
Larry Bates
lbates at syscononline.com
Fri Jan 21 18:41:07 EST 2005
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
>
More information about the Python-list
mailing list