Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

String not printing after regular expression match  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My input is
RFEQ1
 6.1
 5.1
 8.1
 2.1
RDAMP1
 6.1
 6.2
 4.2
 3.1

What I have tried is:

import re

fileName=input("Enter Input File Name: ")
f1=open(fileName,'r')
OutName=input("Enter Output File Name: ")
f4=open(OutName,"w")

class Calculate:
pFreqCount=0
pFreqFlag=0
def freqCal(self,string,freq):
       if (obj.pFreqCount <=3):
           print(string)
           val = float(string)
           res = val + freq
           string =str(res)+"\n"
           self.write(string)

       else:
           obj.write(string)
           obj.pFreqCount = 0
           obj.pFreqFlag = 0
       obj.pFreqCount += 1
def write(self,string):
       f4.write(string)
       
for line in f1.readlines():    
   string=line
   if re.match(r'PFREQ1', string):
       obj.write(string)
       obj.pFreqFlag = 1
   elif obj.pFreqFlag == 1:
       obj.freqCal(string,float(a[30][0]))

   elif re.match(r'RDAMP1', string):
       print(string)
   
   
   else:
       f4.write(string)


Here RDAMP1 is not printing after string search in file. Please help to solve this.Please help me with a code.






 
Greenhorn
Posts: 17
Python VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi itsbinsha, (If I mangled your name, please let me  know.)

Would you re-post your code with the code tags surrounding it please?  I ask because it looks like the indentations of some lines got messed up.  It is not clear what part of the code is part of the class vs. what code is invoking it.

Thanks!
 
Get me the mayor's office! I need to tell him about this tiny ad:
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!