• 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
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!