擅长:python、mysql、java
<p>考虑到<code>','</code>只能作为分隔符出现,我们可以检查行是否有逗号,如果没有,则将其连接到最后一行:</p>
<pre><code>data = []
with open('file.txt', 'r') as text_file:
for line in text_file:
row = line.strip()
if ',' not in row:
data[-1] += '\n' + row
else:
data.append(row)
</code></pre>