with open(r"test.log", encoding='utf-8') as f: # 从TXT文件中读出数据list = []for line1 in f:if line1 != '\n': # 去掉空行l = line1.split() # 这句使用空格将文件内容分割成字符段list.append(l) # 将l放入数组for item in list: # 通过一个for循环将某个字符段下含有某个字符串的行显示出来if len(item) > 1 and item[1] == 'time': # 提取含time字符串的行,使用这个判断是文件中某些行字符长度仅为一个。f = open("time_test.txt", "a") # 将提取出来的行存入新文件中,"a"为追加的方式存入数据f.write(item[6] + "\n")
详细解决方案
python提取文件中含某一字符串的行,并写入新的文件中
热度:79 发布时间:2023-09-28 05:35:54.0
相关解决方案
- ubuntu9.04上安装mic2 出错 (python setup.py build)
- ubuntu9.04下安装mic2 出错 (python setup.py build),该如何解决
- 请教如何理解JAVA、C++ Perl、PHP、Ruby、Python
- python sybase装配
- python(django框架) + mysql 的编码有关问题,求解
- SAE python web.py bootstrap 开发记要
- 数目字代码把大数据数字口语化(python+js) 数字代码
- python JSON string 的中文有关问题
- python――施用yaml数据格式,PK -> XML,JSON
- Learn Python The Hard Way学习(52) - 开始您的web游戏
- Python 相关有关问题
- 菜鸟,先学JAVA,还是Ruby,python
- 生手之前对编程无概念现在想转这行,想尽快入门,java ,python,net、php、C之间如
- 【大哥大姐】python 操作MS SQL Server 2005 效率
- python serial模块运用
- python scp自动登录解决方法
- 【Python】按行读取文件、IOError: [Errno 22] invalid mode ('a+') or filename,处置文件的换行符
- Python 3.x中使用print函数出现语法异常(SyntaxError: invalid syntax)的原因
- 【Error】Python安装gevent时出错:“致命异常: Python.h:没有那个文件或目录”
- [Python]attributeError:'module' object has no attribute 'dump'
- Python 出错:IndentationError: unexpected indent
- Python“TypeError: 'NoneType' object is not iterable"的缘故
- python in操作挑动 TypeError
- 【Error】Python:SyntaxError: Non-ASCII character '\xe5'解决办法
- python 有什么 步骤可以知道函数或类在哪个文件定义的
- 树莓派学习笔记——Python SQLite安插温度记录
- Python 将数组转换为 Wav
- Python:文件格式不正确
- Python-从tkinter脚本连接到远程主机
- 如何在 Bash 的 python 解释器中运行 python 脚本