python中指定行内容替换成另外一行指定的内容
"item":"厁","item":"羐","item":"彳",,"exp":"独自~""item":"銱","item":"臻",,"exp":"渐~佳境|日~完善|...
"item" : "厁",
"item" : "羐",
"item" : "彳",
,"exp" : "独自~"
"item" : "銱",
"item" : "臻",
,"exp" : "渐~佳境|日~完善|百福具~"
"item" : "莪",
"item" : "懑",
,"exp" : "烦~|愁~|忧~"
,"exp" : "愤~"
"item" : "譻",
"item" : "輧",
"item" : "遭",
,"exp" : "~祸︱~遇︱~罪"
,"exp" : "一~生,两~熟"
,"exp" : "跑了一~儿|用绳子绕两~"
"item" : "灯",
"item" : "灯",
用Python如何将text1.txt文件,"exp" : 行的波浪号替换成"item" :行对应的汉字。急用,谢谢各位! 展开
"item" : "羐",
"item" : "彳",
,"exp" : "独自~"
"item" : "銱",
"item" : "臻",
,"exp" : "渐~佳境|日~完善|百福具~"
"item" : "莪",
"item" : "懑",
,"exp" : "烦~|愁~|忧~"
,"exp" : "愤~"
"item" : "譻",
"item" : "輧",
"item" : "遭",
,"exp" : "~祸︱~遇︱~罪"
,"exp" : "一~生,两~熟"
,"exp" : "跑了一~儿|用绳子绕两~"
"item" : "灯",
"item" : "灯",
用Python如何将text1.txt文件,"exp" : 行的波浪号替换成"item" :行对应的汉字。急用,谢谢各位! 展开
1个回答
展开全部
# coding: utf-8
def read():
file_name='test2.txt'
content = open(file_name)
file_end = open('test3.txt', 'wa')
data = ''
for c in content.readlines():
c_array = c.split(':')
if len(c_array) < 2:
file_end.write(c)
continue
elif "item" in c_array[0]:
file_end.write(c)
print c_array[1].split("\"")[1].strip()
data = c_array[1].split("\"")[1].strip()
elif "exp" in c_array[0]:
test = c.replace('~', data)
file_end.write(test)
read()
def read():
file_name='test2.txt'
content = open(file_name)
file_end = open('test3.txt', 'wa')
data = ''
for c in content.readlines():
c_array = c.split(':')
if len(c_array) < 2:
file_end.write(c)
continue
elif "item" in c_array[0]:
file_end.write(c)
print c_array[1].split("\"")[1].strip()
data = c_array[1].split("\"")[1].strip()
elif "exp" in c_array[0]:
test = c.replace('~', data)
file_end.write(test)
read()
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询