码迷,mamicode.com
首页 > 编程语言 > 详细

处理文件中的字符串[python]

时间:2018-04-10 21:54:42      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:read   readline   file   rom   aml   nested   ESS   env   string   

#!/usr/bin/python
#coding:utf-8
"""
"""
import sys,os
from contextlib import nested

def MergeEnvFile(newfile,oldfile):
    with nested(open(newfile,a), open(oldfile, r)) as (new_file, old_file) :
        old_file_lines = old_file.readlines();
        new_file.write(\n);
        new_file.write("  env:");
        new_file.write(\n);
        for line in old_file_lines:
            new_line = line.strip().replace("=",": ",1);
            #Process the second half of the string.
            line_key = new_line.strip().split(":",1)[0];
            line_value = new_line.strip().split(":",1)[1];
            new_line = line_key+": "+"+line_value.strip()+";
            ###############################
            new_file.write(    +new_line);
            new_file.write("\n");
        new_file.close();

if  __name__ == "__main__" :
    MergeEnvFile(temp.yaml,env);

 

处理文件中的字符串[python]

标签:read   readline   file   rom   aml   nested   ESS   env   string   

原文地址:https://www.cnblogs.com/songfucai/p/8782509.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!