Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have my input as

ROLLDIST_STAGE_NO
 1 0 0 0

If my script file in csv, where 27th row and first 4 columns contain any data other than 0,then the 0 in input should be 1 as output otherwise input data should be same as output. For eg: If 27th row contains data as 0,100,0,200 then my output should be

ROLLDIST_STAGE_NO
 1 1 0 1

Please help to solve this. Code help is expecting.


What I have tried:

fileName=input("Enter Input File Name: ")
   f1=open(fileName,'r')
   OutName=input("Enter Output File Name: ")
   f4=open(OutName,"w") 
   scriptName=input("Enter Script File Name(csv): ")
   r=csv.reader((open(scriptName)))
   rownum=0
   a=[]
   for row in r:                #Reading script data
      a.append(row)
      rownum+=1
   class Calculate:
      rollFlag=0
      rollCount=0
      roll=int(a[25][0])
      rtFlag=0
      def write(self,string):
             f4.write(string)
     obj=Calculate()
     for line in f1.readlines():     
     string=line
     elif re.match(r'ROLLDIST_STAGE_NO',string):
         f4.write(string)
         obj.rollFlag=1
     elif(obj.rollFlag==1 and obj.roll==1):
         if obj.rollCount<=1:
             strplit=string.split()
             if(int(a[27][0])!=0):
                st1=1
              else:

               st1=int(strplit[0])
            if int(a[27][1]!=0):
              st2=1
             else:

                st2=int(strplit[1])
             if int(a[27][2]!=0):
                 st3=1
             else:
                 print(strplit[2])
                 st3=int(strplit[2])
             if int(a[27][3]!=0):
                 st4=1
            else:
                st4=int(strplit[3])

             string=str(st1)+"\t"+str(st2)+"\t"+str(st3)+"\t"+str(st4)+"\n"
             obj.write(string)
             obj.rollFlag=0
             obj.rollCount+=1

    else:
         f4.write(string)
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900