关于python写入文件自动换行的问题
作者:路人甲1234 时间:2021-09-01 00:03:13
现在需要一个写文件方法,将selenium的脚本运行结果写入test_result.log文件中
首先创建写入方法
def write_result(str):
writeresult=file(r'D:\eclipse4.4.1 script\my_selenium\model\test_result.log','a+')
str1=writeresult.write(str+'\n')
writeresult.close()
return str
如上str1=writeresult.write(str+'\n') 中写入的文件默认在一行显示,当调用此方法后,每次都会在该文件第一行写入
在写入参数str后加“\n”则会在每次完成写入后,自动换行到下一行,下次写入时便会在下一行写入
来源:https://blog.csdn.net/cuipan1234/article/details/52411319
标签:python,文件,换行
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
趣用文化元素
2009-09-03 11:53:00
![](https://img.aspxhome.com/file/UploadPic/20099/3/0909-using_culture_elements-01-12s.jpg)
不同分辨率下的自适用宽度
2008-11-24 12:58:00
![](https://img.aspxhome.com/file/UploadPic/200811/24/2008112413340367s.jpg)
如何基于pythonnet调用halcon脚本
2022-09-27 16:34:23
![](https://img.aspxhome.com/file/2023/2/67372_0s.png)
如何判断用户在某一页面逗留了多长时间?
2010-01-18 20:48:00
python 实现Flask中返回图片流给前端展示
2023-12-01 06:58:23
Python实现暴力破解wifi密码并打包成exe
2022-04-27 22:24:29
![](https://img.aspxhome.com/file/2023/6/67776_0s.png)
自定义asp错误信息的显示
2007-09-13 12:33:00
如何才能保护好我们的SQL Server数据库
2009-01-08 13:37:00
Python 比较文本相似性的方法(difflib,Levenshtein)
2022-01-29 00:19:17
matplotlib中legend位置调整解析
2023-07-17 03:00:44
![](https://img.aspxhome.com/file/2023/5/77625_0s.png)
pytorch1.0中torch.nn.Conv2d用法详解
2023-07-17 10:53:48
新浪乐居的人不好!哈哈
2009-07-23 20:39:00
![](https://img.aspxhome.com/file/UploadPic/20097/23/sinahouse-26s.jpg)
Oracle 数据库 临时数据的处理方法
2009-07-02 11:48:00
Mootools 1.2教程(9)——输入过滤第二部分(字符串)
2008-12-01 12:25:00
PyQt5+python3+pycharm开发环境配置教程
2022-11-03 03:34:11
![](https://img.aspxhome.com/file/2023/0/80740_0s.png)
python中sys模块是做什么用的
2021-04-30 10:04:48
Django Python 获取请求头信息Content-Range的方法
2022-09-09 07:04:53
python读取和保存图片5种方法对比
2022-05-27 23:54:32
python用BeautifulSoup库简单爬虫实例分析
2022-04-02 21:42:00
Python中的多线程实例(简单易懂)
2021-12-07 04:09:47
![](https://img.aspxhome.com/file/2023/7/80447_0s.png)