ValueError: too many values to unpack
Pablo Ziliani
pablo at decode.com.ar
Thu Sep 27 21:23:13 EDT 2007
Zentrader wrote:
> On Sep 27, 9:46 am, Shawn Minisall <trekker... at comcast.net> wrote:
>
>> line 3 - 19.18 29.15 78.75 212.10
>> line 4 - 100 20 410.29
>> And this is the code I'm using:
>>
>> #read withdrawls from file on line3
>> line = infile.readline()
>> #split withdrawls up
>> withdraw1, withdraw2, withdraw3, withdraw4 = string.split(line, "\t")
>>
>> #read deposits from file on line4
>> line = infile.readline()
>> #split deposits up
>> deposit1, deposit2, deposit3 = string.split(line, "\t")
>>
>> I have 4 strings to match line 3 and 3 to match the 3 on line 4...any
>> thoughts?
>>
>
> A string.split returns a list so you don't have to know how many
> elements there are beforehand. A simple example
> withdraw = line.split("\t")
> if len(withdraw) == 3:
> match_3(withdraw)
> elif len(withdraw) == 4::
> match_4(withdraw)
> else:
> print "line.split() is not 3 or 4", withdraw
Right, and then because error was caused for an unexpected extra tab you
made the deposit pass as a withdrawal...
Not everybody trades just Zen :)
(tip: the unpacking mystery has been solved earlier this day)
Regards,
Pablo
More information about the Python-list
mailing list