ValueError: too many values to unpack

fscked fsckedagain at gmail.com
Wed Apr 11 15:28:08 EDT 2007


On Apr 11, 10:26 am, Laszlo Nagy <gand... at designaproduct.biz> wrote:
> fscked írta:> Trying to use CSV to read in a line with 11 fields and I keep getting
> > this error. I have googled a bit and have been unable to figure it out.
>
> Probably you have more than 11 values in some (or all) of the rows in
> the CSV file. Try this code:
>
> L = (1,2,3,4,5)
> a1,a2,a3 = L
>
> If you are sure that you only need a certain number of values, "the
> first N columns":
>
> a1,a2,a3 = L[:3]
>
> Then you still can have a "not enough values to unpack" error, guess
> what that means. ;-)
>
>    Laszlo

Hmm, well I have counted the fields in the CSV and verified there are
only 11. Here is the offending code:

myfile = open('ClientsXMLUpdate.csv')
csvreader = csv.reader(myfile)

for boxid, mac, activated, hw_ver, sw_ver, heartbeat, name, address,
phone, country, city in csvreader:
	mainbox = SubElement(root, "{Boxes}box")
	mainbox.attrib["city"] = city
	mainbox.attrib["country"] = country
	mainbox.attrib["phone"] = phone
	mainbox.attrib["address"] = address
	mainbox.attrib["name"] = name
	mainbox.attrib["pl_heartbeat"] = heartbeat
	mainbox.attrib["sw_ver"] = sw_ver
	mainbox.attrib["hw_ver"] = hw_ver
	mainbox.attrib["date_activated"] = activated
	mainbox.attrib["mac_address"] = mac
	mainbox.attrib["boxid"] = boxid

I just don't get it... :/




More information about the Python-list mailing list