Difference between revisions of "Python - File Processing"

From PeformIQ Upgrade
Jump to navigation Jump to search
(New page: Here is a fragment of code with some simple file parsing logic... <pre> def analyse(logfile): cnt = 0 lfd = open(logfile, 'r') for line in lfd.readlines(): if cnt ==...)
(No difference)

Revision as of 15:44, 4 April 2008

Here is a fragment of code with some simple file parsing logic...

def analyse(logfile):
   cnt = 0

   lfd     = open(logfile, 'r')

   for line in lfd.readlines():
      if cnt == 11:
         response_xml = line[:-1]
         print "[[%s]]" % response_xml
      print "Cnt -> %d" % cnt
      cnt += 1

   lfd.close()

   ofd = open('response.xml', 'w')

   ofd.write(response_xml)
   ofd.close()

   return response_xml