BraveZhao的个人博客分享 http://blog.sciencenet.cn/u/BraveZhao

博文

Python删除VASP CONTCAR文件中的空白行

已有 2380 次阅读 2018-10-31 17:24 |个人分类:Python|系统分类:科研笔记

 
#!/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()为一次性读取全部内容


https://blog.sciencenet.cn/blog-3388193-1143802.html

上一篇:在VMware下的Ubuntu中访问集群
下一篇:Python提取bandstructure文件中的第一列的某些数据
收藏 IP: 218.94.136.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-3-28 23:26

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部