Python ValueError: too many values to unpack with glob
Question: I'm trying to load two sets of CSV files and do some calculations on both such
as difference of each set, mean absolute error `set1 - set2` exc.

I'm trying to load both sets like this:

    
    
    import glob    
    for a, b in (glob.glob("*a.csv"), glob.glob("*b.csv")):
    

And I get the error:

    
    
    ValueError: too many values to unpack
    


Answer: # The Problem

You are getting the `ValueError` because you are trying to assign more items
to the tuple than the number of target variables you provide. The for loop
tuple unpacking syntax will loop through each list in your tuple and attempt
to assign each value in the tuple to your targets (`a` and `b`). For instance,
this would work:

    
    
    for a,b in (['0a.csv', '1a.csv'], ['0b.csv', '1b.csv']):
        print a,b
    

It assigns the first value of each list to `a` and the second value to `b`.
The code above prints:

    
    
    0a,csv 1a.csv
    0b.csv 1b.csv
    

Thus, you are getting the `ValueError` because the results from at least one
of your `glob.glob` calls is a list longer than two elements.

# A Solution

Based on what you are trying to do, I think you want to use
[`zip`](http://docs.python.org/library/functions.html#zip).

    
    
    import glob
    
    for a,b in zip(glob.glob("*a.csv"), glob.glob("*b.csv")):
        # whatever
    

That will take pairs of files matching the pattern you gave and assign them to
`a` and `b`. For example, if you have files `0a.csv`, `1a.csv`, `2a.csv`,
`0b.csv`, `1b.csv`, and `2b.csv` doing

    
    
    for a,b in zip(glob.glob("*a.csv"), glob.glob("*b.csv")):
        print a, b
    

results in

    
    
    0a.csv 0b.csv
    1a.csv 1b.csv
    2a.csv 2b.csv
    

