||
#!/usr/bin/python # -*- coding: UTF-8 -*- #coding=utf-8 import os #删除contar中的带有0的行 path1="G:/CONTCAR" with open(path1,'r') as r: lines=r.readlines() with open(path1,'w') as w: for l in lines: if '0.00000000E+00 0.00000000E+00 0.00000000E+00' not in l: w.write(l) with open(path1, "r") as contcar: text = contcar.read() print(text) python的数据写入功能分为全新写入和追加写入,全新写入就是上面的写入方式 r.readlines()为按行读取,并且希望将读取的内容全部放到一个列表中 contar.read()为一次性读取全部内容
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-9-27 09:17
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社