#!/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(' '); new_file.write(" env:"); new_file.write(' '); 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(" "); new_file.close(); if __name__ == "__main__" : MergeEnvFile('temp.yaml','env');