Beginner question on text processing

skip at pobox.com skip at pobox.com
Fri Dec 29 09:14:10 EST 2006


    Harold> To illustrate, assume I have a text file, call it test.txt, with
    Harold> the following information:

    Harold> X11 .32
    Harold> X22 .45

    Harold> My goal in the python program is to manipulate this file such
    Harold> that a new file would be created that looks like:

    Harold> X11 IPB = .32
    Harold> X22 IPB = .45

    ...

This is a problem with a number of different solutions.  Here's one way to
do it:

    for line in open(filename, "r"):
        fields = line.split()
        print fields[0], "IPB =", fields[1]

Skip



More information about the Python-list mailing list