with open('a.txt') as f:
with open('b.txt','w') as f1:
content=f.readlines()for line in content:
key='NumberInt'if key not in line:
f1.write(line)else:print(line)
f1.close()
f.close()
python读取文件并删掉部分内容文章目录python读取文件并删掉部分内容想要把文档里的列表数据读成python中的列表数据,发现里面的NumberInt数据类型不能被识别,因此要处理掉代码如下:with open('a.txt') as f: with open('b.txt','w') as f1: content=f.readlines() for line in content: key='NumberInt'