Python 2.7 如何在Python中写入和读取文件中的许多URL?

Python 2.7 如何在Python中写入和读取文件中的许多URL?,python-2.7,io,Python 2.7,Io,我用python 2.7编写了这段代码,用于在文本文件中编写URL f = io.open('./pages/page%s' % str(self.pageNumber), 'w+', encoding='utf-8') f.write(unicode(response.url)) f.close() self.pageNumber = self.pageNumber + 1 如何将所有response.url放在一个文件中(逐行)而不是许多页面,然后如何逐行读取此url 我回答我自己的问题:

我用python 2.7编写了这段代码,用于在文本文件中编写URL

f = io.open('./pages/page%s' % str(self.pageNumber), 'w+', encoding='utf-8')
f.write(unicode(response.url))
f.close()
self.pageNumber = self.pageNumber + 1

如何将所有response.url放在一个文件中(逐行)而不是许多页面,然后如何逐行读取此url

我回答我自己的问题:


我应该使用a而不是w

@MattDMo谢谢,我阅读了它,并以此编写了我的代码,但我不知道如何将所有结果放在一个文件中而不被覆盖,类似于shell中的>>我使用for循环,但最后我只有最后一个url,我不知道如何不覆盖到我的文件并拥有我所有的url