1 with open('demo1_lock3.txt','r',encoding='utf-8') as ff: 2 file=ff.read() 3 sight=file.split() 4 lihua=[] 5 for i in sight: 6 dict={} 7 8 ii=i.strip().split(':') 9 for z in range(len(sight)): 10 dic[sight[0]]=ii[z] 11 # while '[{' in dic: 12 #这里原本想删除这个符号的,后来没想起来怎么操作 13 #pass 1 15 lihua.append(dict) 16 print(lihua)
with open('demo1_lock3.txt','r',encoding='utf-8') as ff: file=ff.read() sight=file.split() lihua=[] for i in sight: dic={} ii=i.strip().split(':') for z in range(len(sight)): dic[sight[0]]=ii[z] # while '[{' in dic: #这里原本想删除这个符号的,后来没想起来怎么操作 #pass #重点注意:在这里分割的是用ii,不是li,在这个地方纠结了好长时间 lihua.append(dic) print(li标签:文件,file,读取,python,lihua,dic,ii,split,sight From: https://www.cnblogs.com/sunnywf/p/16758916.html