My input string from a file is
ANG
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
My required output should be
ANG
0.0
0.0
0.0
0.0
0.0
0.0
100
0.3
但是现在我的输入与输出相同。ANG字符串下的最后两个零将分别替换为100.0和0.3。请帮助我获取所需的输出。
import re
class Calculate:
def angCal(self,direction,magnitude,string):
cnt=0
if cnt<=6:
f4.write(string)
cnt+=1
elif cnt==7:
string=str(direction)+"\n"
f4.write(string)
cnt += 1
elif cnt==8:
string = str(magnitude) + "\n"
f4.write(string)
cnt += 1
elif cnt==9:
cnt += 1
angFlag=0
angcnt=0
f1=open("nominal.txt","r")
f4=open("pp.txt","w")
obj=Calculate()
for line in f1.readlines():
string=line
if re.match(r'ANG',string):
angFlag=1
f4.write(string)
elif angFlag==1 and angcnt==0:
direction=100
magnitude=0.3
print(string)
obj.angCal(direction,magnitude,string)
angFlag=0
angcnt+=1
elif angFlag==1 and angcnt==1:
direction=315
magnitude=0.4
else:
f4.write(string)
请帮助获取所需的输出。如何将一组字符串传递给函数。期待代码帮助