附代码:ftel1=open('tele.txt','rb')ftel2=open('email.txt','rb')ftel1.readline()ftel2.readline()lines1=ftel1.readline()lines2=ftel2.readline()dic1={}dic2={}for line in lines1: elements=line.split(' ') dic1[elements[0]]=str(elements[1].decode('gbk'))for line in lines2: elements=line.split(' ') dic2[elements[0]]=str(elements[1].decode('gbk'))line=[]lines.append('姓名\t 电话 \t 邮箱\n')for key in dic1: s='' if key in dic2.keys(): s='\t'.join([str(key.decode('gbk')),dic1[key],dic2[key]]) s+='\n' else: s='\t'.join([str(key.decode('gbk')),dic1[key],str('------')]) s+='\t' lines.append(s)for key in dic2: s='' if key in dic1.keys(): s='\t'.join([str(key.decode('gbk')),str('------'),dic2[key]]) s+='\t' lines.append(s)ftel3=open('book.txt','w')ftel3.writelines(lines)ftel1.close()ftel2.close()ftel3.close()谢谢指教 用的python3.6
添加回答
举报
0/150
提交
取消