Click here to Skip to main content
14,024,527 members
Rate this:
 
Please Sign up or sign in to vote.
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web02 | 2.8.190419.4 | Last Updated 12 Nov 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100