Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

String not printing after regular expression match  RSS feed

 
Greenhorn
Posts: 3
  • 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: 26
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!
 
Poop goes in a willow feeder. Wipe with this tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!