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>In this line:</p>

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

<p>you assign the result of <code>SampleLvl</code> to 2 variables, but your function, <code>SampleLvl</code>, that you seem to call recursively in that line, returns a 4-tuple.
I assume that <code>self.fn.SampleLvl</code> is the same function you're in already.
If that's the case you've also omitted the <code>mods</code> param in the call.</p>

<p>Another remark is that a bit more context would be handy. I just assume that there's only one <code>SampleLvl</code>, so <code>self==self.fn</code>, but there may in fact be 2 different functions with the same name involved, which, without context, I find confusing.</p>

python python-2.7