有些测试功能不能将数据写入到数据库,因为服务器可能不会为此功能再创建数据表或修改原表,因此在测试期间用文件存储还是很有必要的,若直接移植到服务器中也不必新建数据库表。
本人小白一枚,只将查找到的资料应用后整理如下,既方便自己后续查询,也希望能帮助到小伙伴们。
-----------------------------------------------------------------------------------------------------
1、在文本文件的最上层添加数据
write_fileroute='文件路径'
with open(write_fileroute,'r+') as f:
old=f.read()
f.seek(0)
f.write('new line\n'+old)
2、在文本文件最下层追加数据
write_fileroute="文件路径"
with open(write_fileroute,'a') as f:
f.write('.....\n')
3、