ScottChang25

PythonWin2.6.5:open a text file, read it into memory, and then print each line-fails

Discussion created by ScottChang25 on Nov 6, 2012
Latest reply on Nov 8, 2012 by mahunter243
Hi all,
In Python Win 2.6.5, I executed the following Python script on the attached txt file:
# open the text file, read it into memory
file = open('c:/testing/a-little-more-involved.txt').read().splitlines()
# define a new, empty list object
l = []
# iterate through the lines of the file, slice up the line by index
#   position of each data column
for line in file:
    v0 = line[0:3]
    v1 = line[3:18].strip()
    v2 = line[18:19]
    v3 = line[19:20]
    v4 = line[20:21]
    v5 = line[21:26]
    v6 = line[26:27]
    v7 = line[27:29]
    # add the parsed items to list l; as we go through the lines,
    #   we create a nested list
    l.extend([[v0,v1,v2,v3,v4,v5,v6,v7]])
# iterate through list, print out members
for each in l:
    print each


It does not work at all - no error and no output.  Please kindly help and advise me how to fix the problem.

Thanks in advance,
Scott Chang

Attachments

Outcomes