擅长:python、mysql、java
<p>我不明白为什么你还没有提供我(和其他人)要求的额外信息,所以下面的建议充其量只是一个有根据的猜测,实现了我在一个评论中向你建议的内容(即将<code>h_list</code>转换成一个包含单个字符串的列表列表):</p>
<pre><code>import csv
h_list = [
"Here's Why There Was an Empty Seat Next to Prince William at the Royal Wedding",
"NASA wrestles with what to do with International Space Station after 2024",
"Father-son team pilot plane from Seattle to Amsterdam",
# etc...
]
with open('headlines.csv', 'w', newline='') as o_file:
writer = csv.writer(o_file)
# Make each line in h_list a row with a single headline string in it.
writer.writerows([headline] for headline in h_list)
print('done')
</code></pre>
<p>执行后<code>headlines.csv</code>的内容:</p>
^{pr2}$
<p>我不确定您是否希望在<code>csv</code>文件中使用这种格式,因为当每行中只有一个值(字段)时(因此不需要分隔符),使用这种格式实际上没有多大意义—但是,如果没有其他内容,也许它将帮助您找到正确的方法。</p>