本文介绍了如何在python 2.7.11中将数据追加到文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以告诉我如何将超链接添加到文本文件中的新行吗?如果文本文件的第一行中已经有数据,我希望将数据插入到下一个空行中.我正在将多个超链接写入文本文件(附加).预先感谢.
Could any one show me how i can add hyperlinks to new line in text file? If there is already data in first line of text file i want the data get inserted in the next empty line. I am writing multiple hyperlinks to text file(append). Thanks in advance.
print "<a href=\"http://somewebsite.com/test.php?Id="+str(val)+"&m3u8="+lyrics+"&title=test\">"+str(i)+ "</a> <br />";
推荐答案
看看python 文档.
您可以使用with open
语句打开文件.
You can use the with open
statement to open the file.
with open(filename, 'a') as f:
f.write(text)
这篇关于如何在python 2.7.11中将数据追加到文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!