早教吧作业答案频道 -->英语-->
python文件操作问题有a.txt其中文件的格式为goodlikebecarefulhelloworld有b.txt其中文件的格式为:nihaogoodlikebeworldbecareful有c.txt其中文件的格式为:(c文件的值与b文件的短语每一行相互对应)1
题目详情
python文件操作问题 有a.txt其中文件的格式为
good like
be careful
hello world
有b.txt其中文件的格式为:
ni hao
good like
be world
be careful
有c.txt其中文件的格式为:(c文件的值与b文件的短语每一行相互对应)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
1 2 3 5 4 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
1 2 3 4 5 6 8 7 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
1 2 3 4 5 6 7 8 9 10 12 14 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
现在要求生成一个d.txt其中存放a文件在b文件中查找到短语对应的值,若a文件中的短语没有在b文件中的出现,则统一用50个0值表示.存储格式为:
good like
1 2 3 5 4 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
be careful
1 2 3 4 5 6 7 8 9 10 12 14 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
hello world
0 0 0.0(50个0)
good like
be careful
hello world
有b.txt其中文件的格式为:
ni hao
good like
be world
be careful
有c.txt其中文件的格式为:(c文件的值与b文件的短语每一行相互对应)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
1 2 3 5 4 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
1 2 3 4 5 6 8 7 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
1 2 3 4 5 6 7 8 9 10 12 14 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
现在要求生成一个d.txt其中存放a文件在b文件中查找到短语对应的值,若a文件中的短语没有在b文件中的出现,则统一用50个0值表示.存储格式为:
good like
1 2 3 5 4 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
be careful
1 2 3 4 5 6 7 8 9 10 12 14 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
hello world
0 0 0.0(50个0)
▼优质解答
答案和解析
txtpath2=r"b.txt"
txtpath3=r"c.txt"
txtpath4=r"d.txt"
fpa=open(txtpath1)
fpb=open(txtpath2)
fpc=open(txtpath3)
fpd=open(txtpath4,"w")
arrD=[]
for kkk in range(50):
arrD.append(0)
def WriteD():
for kkkk in arrD:
fpd.write(str(kkkk))
fpd.write(" ")
fpd.write("\n")
arrC=[]
for linec in fpc.readlines():
arrC.append(linec.replace("\n",""))
arrB=[]
for lineb in fpb.readlines():
arrB.append(lineb.replace("\n",""))
for linea in fpa.readlines():
flag=True
linea=linea.replace("\n","")
for i in range(len(arrB)):
if arrB[i]==linea:
print linea
print arrB[i]
print arrC[i]
flag=False
fpd.write(linea)
fpd.write("\n")
fpd.write(arrC[i])
fpd.write("\n")
if flag:
print linea
fpd.write(linea)
fpd.write("\n")
WriteD()
print "Done!"
fpa.close()
fpb.close()
fpc.close()
fpd.close()
你好:
请看代码:
txtpath1=r"a.txt"txtpath2=r"b.txt"
txtpath3=r"c.txt"
txtpath4=r"d.txt"
fpa=open(txtpath1)
fpb=open(txtpath2)
fpc=open(txtpath3)
fpd=open(txtpath4,"w")
arrD=[]
for kkk in range(50):
arrD.append(0)
def WriteD():
for kkkk in arrD:
fpd.write(str(kkkk))
fpd.write(" ")
fpd.write("\n")
arrC=[]
for linec in fpc.readlines():
arrC.append(linec.replace("\n",""))
arrB=[]
for lineb in fpb.readlines():
arrB.append(lineb.replace("\n",""))
for linea in fpa.readlines():
flag=True
linea=linea.replace("\n","")
for i in range(len(arrB)):
if arrB[i]==linea:
print linea
print arrB[i]
print arrC[i]
flag=False
fpd.write(linea)
fpd.write("\n")
fpd.write(arrC[i])
fpd.write("\n")
if flag:
print linea
fpd.write(linea)
fpd.write("\n")
WriteD()
print "Done!"
fpa.close()
fpb.close()
fpc.close()
fpd.close()
看了python文件操作问题有a....的网友还看了以下:
设随即变量X~N(u,e),术Y=X-u/e的概率密度. 2020-04-12 …
热学ΔE,ΔH,q,w,ΔU,ΔE,ΔH,q,w,ΔU,怎么好像ΔE,ΔU都是内能的意思.有什么区 2020-04-27 …
设函数f(u)具有二阶导数,而z=f((e^x)*sin(y))满足方程d^2(z)/d^2(x^ 2020-05-16 …
椭圆方程式的题椭圆方程x^2/a^2+y^2/b^2=t怎么用y=f(u),x=f(u)表示如果椭 2020-05-16 …
o,s,h,u,e.能组什么单词? 2020-06-05 …
在风险分析中E(u(x))和U(E(X))分别是什么意思 2020-06-10 …
e^x^2求导看成f'(u)f(u)=u^2u=e^x------>f'(u)=2u*u'=2e^ 2020-06-12 …
积分1/(根号下1+e的2x次幂)dx怎么推导的.令u=e^(-x),du=-e^(-x)dx,1 2020-07-29 …
电场中U=Ed,U我们学习的时候类比为高度h,E我们类比为g,有E=U/d,那么h/g等于什么?写错 2020-11-29 …
是高数王子的请进a.limf(x)g(x)=limh(x)如果右边存在且limf(x)存在那么lim 2020-12-10 …