sosman <ne****@metrak.KILLSPAM.com> wrote in
news:40**********************@news.optusnet.com.au :
I take it python doesn't support defaults when assigning to a tuple, eg:
for line in file:
(parameter, value, units = 'kg') = line.split()
along the lines of default parameter assignment in function calls.
You take it correctly. It isn't too hard to get a similar effect though:
parameter, value, units = (line.split() + ['kg',])[:3]
Of course, if the line splits into more than 3 words this version fails to
throw any kind of error. If you want an error to be thrown, how about
:
def pvu(parameter, value, units='kg'):
return parameter, value, units
parameter, value, units = pvu(*line.split())