Formatting input text file

Edwin.Madari at Edwin.Madari at
Thu Aug 14 15:59:22 CEST 2008

save following code in, and run it as 'python <your-data-file>'
with your sample data this prints out following which is what you are looking for (i think)
3.08333 9.05526 3.13581
4.08322 4.02526 3.95891
import sys

data = []
row = []
fh = open(sys.argv[1])
for line in fh:
   line = line.strip()
   if not line or line.startswith('....'):
   if line.startswith('X'):
      if row:
         row = []
if row:

for  i in data:
   print ' '.join(i)

good luck.
-----Original Message-----
From: at
[ at]
On Behalf Of victor.herasme at
Sent: Thursday, August 14, 2008 7:07 AM
To: python-list at
Subject: Formatting input text file


it's me again with tons of questions. I hava an input file structured
like this:

                  X               XYData-1

                1.                 3.08333
                2.                 9.05526
                3.                 3.13581

                  X               XYData-2

                1.                 4.08322
                2.                 4.02526
                3.                 3.95891

i want to format it so i only get the second column, in order to place
it in a mxn matrix. Let's say i want this:

number1   number2   number3
number4   number5   number6

i hope it is not too hard to do. Any help greatly apreciated. Thanks,


The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.

More information about the Python-list mailing list