擅长:python、mysql、java
<p><code>w+b</code>中的<code>b</code>很可能是问题的一部分,因为这将使文件被视为二进制文件,因此换行符按原样编写。在</p>
<p>所以第一步是删除<code>b</code>。然后通过添加<code>U</code>还可以激活通用换行支持(请参见:<a href="https://docs.python.org/3/glossary.html#term-universal-newlines" rel="nofollow noreferrer">https://docs.python.org/3/glossary.html#term-universal-newlines</a>)</p>
<p>所以这条线应该是这样的:</p>
<pre><code>file = open('%s_items.csv' % spider.name, 'Uw+')
</code></pre>