Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • String Passing in Python Class Methods - Output Error

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 431
    Answer it

    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 0.0 0.0 0.0 0.0 0.0 0.0 100 0.3 But Now my input is same as output .The last two zeroes under ANG string to be replaced as 100.0 and 0.3 respectively.Please help me to get the required output.

    What I have tried:

    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:

 0 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: