擅长:python、mysql、java
<p>问题是<code>namedtuple()</code>的返回值及其<code>typename</code>参数的大小写是不同的。也就是说,命名元组的类定义和您给它的变量名不匹配。你需要两者匹配:</p>
<pre><code>LogEntry = namedtuple("LogEntry", ['logLev', 'msg'])
</code></pre>
<p>并相应地更新<code>doSomething()</code>中的<code>return</code>语句。在</p>
<p>完整代码:</p>
^{pr2}$
<p>(要查看类定义,请将<code>verbose=True</code>添加到<code>namedtuple()</code>。)</p>