BinshaS Ответов: 0

Заменить строку новыми данными


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.


Что я уже пробовал:

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)

0 Ответов