python 文本文件数据处理
#/usr/bin/env python3
# -*- coding: utf-8 -*-
def zhidao_560604345(infile, outfile):
reader = open(infile, ‘r’)
set_dict = {}
setenv_dict = {}
while True:
line = reader.readline()
if len(line) == 0:
break
a, b, c = line.strip().split(maxsplit=2)
if a == ‘set’:
if not b in set_dict:
set_dict[b] = set()
set_dict[b].add(c.strip())
elif a == ‘setenv’:
if not b in setenv_dict:
setenv_dict[b] = set()
setenv_dict[b].update(c.strip().split(‘:’))
reader.close()
buff = []
for k, v in set_dict.items():
buff.append(‘set %s “%s”‘ % (k, ‘:’.join(list(v))))
for k, v in setenv_dict.items():
tmp = []
for