擅长:python、mysql、java
<p>这里有一种方法-先在逗号上拆分,然后在多个空格上拆分,以避免拆分单间距的名称。然后用逗号将所有项目与<code>str.join</code>连接起来:</p>
<pre><code>with open(textfile) as f, open(csvfile, 'w') as fc:
for line in f:
first, others = line.split(',')
row = [first] + [i.strip() for i in others.split(' ') if i]
fc.write(','.join(row) + '\n')
</code></pre>