Python ValueError: too many values to unpack in a While loop
<p>I am getting this exception from the following code and mainly form the second line in the while loop, any hint please? Thank you.</p>

<pre><code>def SampleLvl(self, mods, inds, M):
    calcM = 0
    total_time = 0
    p = np.arange(1, self.last_itr.computedMoments()+1)
    psums_delta = _empty_obj()
    psums_fine = _empty_obj()
    while calcM &lt; M:
        curM = np.minimum(M-calcM, self.params.maxM)
        values, samples_time = self.fn.SampleLvl(inds=inds, M=curM)
        total_time += samples_time

        delta = np.sum(values * \
                       _expand(mods, 1, values.shape),
                       axis=1)
        A1 = np.tile(delta, (len(p),) + (1,)*len(delta.shape) )
        A2 = np.tile(values[:, 0], (len(p),) + (1,)*len(delta.shape) )
        B = _expand(p, 0, A1.shape)
        psums_delta += np.sum(A1**B, axis=1)
        psums_fine += np.sum(A2**B, axis=1)
        calcM += values.shape[0]

    return calcM, psums_delta, psums_fine, total_time
</code></pre>

<p>I got this error</p>

<p>, line 740, in SampleLvl
    values, samples_time = self.fn.SampleLvl(inds=inds, M=curM)
ValueError: too many values to unpack</p>

<p>You will get a <code>ValueError: too many values to unpack</code> when you try and assign more variables into less variables. </p>

<p>For example, if you had a function <code>foo()</code> which returns <code>(a, b, c)</code> you could do: <code>a, b, c = foo()</code> but you would get an error if you tried to do <code>a, b = foo()</code> as the function returns more variables than you are trying to assign to. </p>

<p>You do this here:</p>

<pre><code>values, samples_time = self.fn.SampleLvl(inds=inds, M=curM)
</code></pre>

<p>Hope this helps! </p>

python python-2.7