[Tutor] newbie text parsing question

Rob rob@uselesspython.com
Wed, 28 Aug 2002 11:31:33 -0500


There are different ways to get to the solution you're after. Do you want to
code for a situation in which you know you will always expect the same
format to the file, or do you want to account for files that don't have
precisely the same format?

For instance, will you always have only one "Problem:" listed?

Do you already have the grasp of reading and writing files to your
satisfaction? The Tutorial that tends to come ship with Python distributions
(and also easily found at python.org) has a section demonstrating File I/O.

There are also lots of samples out there, at sites like the Vaults of
Parnassus, the Python Cookbook site, and Useless Python.

Rob

-----Original Message-----
From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of Ron
Nixon
Sent: Wednesday, August 28, 2002 10:57 AM
To: tutor@python.org
Subject: [Tutor] newbie text parsing question


Ive got a file that looks like this:
   Case Number: 076-2000  Recall Notification Report:  RNR076-2000
   Date Opened: 12/20/2000  Date Closed:  04/20/2001
   Recall Class:  1  Press Release (Y/N):  Y
   Domestic Est. Number:  02040  M     Name:  Harper's Country Ham
   Imported Product (Y/N):  Y      Foreign Estab. Number:  N/A
   City:  Clinton   State:  KY  Country:  USA
   Product:  Country Ham
   Problem:  BACTERIA  Description: LISTERIA
   Total Pounds Recalled:  10,400  Pounds Recovered:    7,561

I'd like to be able to read all of the file in a extract the data following
the Title and ":" to produce some like this:
076-2000, RNR076-2000,04/20/2001,04/20/2001,1,Y,02040  M, Harper's Country
Ham, etc
that I can then import into a spreadsheet or database. I found nothing at
the Python.org site nor in the Text Processing using Python book. Any ideas?
thanks in advance

Ron




Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes