Python文件的读取与写入

老朽八百岁 2019-04-19 08:34:16
h=open('pinyin_score.txt','w') count = len(open('name_pinyin.txt','r').readlines()) name1_list=[] name2_list=[] count = len(open('name_pinyin.txt','r').readlines()) with open('name_pinyin.txt','r') as f1 , open('name_score.txt','r') as f2: name1=f1.readlines() name2=f2.readlines() for i in (0,count-1): for j in (0,count-1): if (name1[i].split(',',1)==name2[j].split(' ',1)): print("%s %s" %(name1[i].split(',' , '\n', 2),name2[j].split(' ','\n',2)),file=h,end='') else: pass f1.close() f2.close() h.close() 为什么写入的文件夹是空的?
...全文
34 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧