2024-09-24 10:28:48 发布
网友
从rss提要中,我可以从每个提要中提取内容,但现在我尝试将每个输出保存到单独的txt文件中,并使用它们的标题,例如newstTitle1.txt、newstTitle2.txt……但到目前为止,使用下面的代码,它只保存列表中的最后一个输出。有没有办法解决这个问题
with open('textfile.txt', 'w') as handle: handle.write(text) counter+=1
# somewhere in code counter = 0 # in place where you save it with open('textfile' + str(counter) + '.txt', 'w') as handle: handle.write(text) counter+=1
或者如果变量newstitle中有标题
newstitle
with open(newstitle + '.txt', 'w') as handle: handle.write(text)
注意文件名中的本地字母、空格和其他奇怪字符
或者如果变量
newstitle
中有标题注意文件名中的本地字母、空格和其他奇怪字符
相关问题 更多 >
编程相关推荐