Pretty simple code, I have a tuple extraAccessions with two values, a string and a list. I want to loop through the extraAccessions (which is only one in this example) and use the first and second values in the tuple.
extraAccessions=('MS:1000505',['value','unitName'])
for accession, fieldIdentifiers in extraAccessions:
[do something]
However, this gives
ValueError: too many values to unpack
When I do
print (extraAccessions)
I get
('MS:1000505', ['value', 'unitName'])
Which seems two values to me, exactly what is asked in
for accession, fieldIdentifiers in extraAccessions:
So I don’t see why I get this error.
edit:
And when I do
for accession in extraAccessions:
print accession
I get the first element MS:1000505
Let’s examine your code:
Here, you are iterating over the tuple (
extraAccessions) that has two entries:'MS:1000505'['value','unitName']You’re then trying to unpack each entry in turn into the two variables. This doesn’t work for the first entry since it is not of length two.
If you’re looking to unpack the two entries into the two variables, simply use:
That will set
accessionto'MS:1000505'fieldIdentifiersto['value','unitName']