Interesting dilemma - See if you can help.

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2009
Posts: 82
Reputation: P00dle is an unknown quantity at this point 
Solved Threads: 1
P00dle's Avatar
P00dle P00dle is offline Offline
Junior Poster in Training

Interesting dilemma - See if you can help.

 
0
  #1
Nov 5th, 2009
Hi,

I have stumbled on an interesting problem. I have thought 'n' thought, but haven't come up with any good ideas of how to handle this.

I have a text file that contains many records, but without the records being seperated. I need to figure out how to seperate these files, or at least how to write a program that recognizes different records and can then seperate them.

I don't expect anyone to write my program for me, but I need help seperating the records.

The beginning of every record looks like this: MSUBUGA JIMSON
P O BOX 21273
GABORONE
(Obviously they are all different, but always have 3 values on 3 lines.)
The end looks like this:
P107.17 P0.00 P225.08 P0.00 P332.25
(The numbers always vary, but there are always 5)

Any help will be greatly appreciated, Thank you.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,067
Reputation: jlm699 is a jewel in the rough jlm699 is a jewel in the rough jlm699 is a jewel in the rough jlm699 is a jewel in the rough 
Solved Threads: 267
Sponsor
jlm699's Avatar
jlm699 jlm699 is offline Offline
Knows where his Towel is
 
0
  #2
Nov 5th, 2009
Originally Posted by P00dle View Post
The beginning of every record looks like this: MSUBUGA JIMSON
P O BOX 21273
GABORONE
(Obviously they are all different, but always have 3 values on 3 lines.)
The end looks like this:
P107.17 P0.00 P225.08 P0.00 P332.25
(The numbers always vary, but there are always 5)
So each record is 4 lines total (with only 3 lines we care about).

Can you give an small snippet of a file with at least two records for example? I envision either simply taking every 4 lines and parsing out the relevant info, or if there is a blank line between each record, just split at the blank lines.

If you read the file in with readlines() , using index slicing you can easily grab groups of lines.
1. Use Code Tags.
2. Homework? Show Effort.
3. Keep discussions on the forum: no PMs
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC