Hi everyone,

I'm a relative beginner in python looking for a bit of help on an error I get when running the script posted below. It is used to split data files in text mode. It runs through a list of files (using the glob module) and creates a number of data files out of each one. I'm getting wrong results for only some of the files in the list: the first 2 are OK, then the next 12 are showing wrong results, then the last 8 are OK. I'm doing this under windows XP Pro using python 2.5.1. The weird thing is that when I use the debugger under Pythonwin and step through the loop in which data is read from the source file and written to the output, the problem disappears. Does someone have a clue what the problem might be? I'm enclosing two of the source files, the first one in the list (which produces correct output) and the first one which is not processed properly. The first files output from each of these source files are also enclosed. In the one where the problem occurs, the data lines are wrong: instead of having 5 real numbers separated by a certain number of spaces, only the first number in each line is correct, the rest are replaced by zeros.

Many thanks in advance for any help.

Jacques

the script follows:

import glob

DIR='I:\\raw\\'

for filename in glob.glob(DIR+'*.tbl'):
    file=open(filename,'r')
    line_name = filename.strip().split('\\')[-1].split('.')[0].split('_')[0]
    line = 'i'
    while line != '':
        while line[0] != 'SITE':
            line=file.readline().strip().split(':')
        station_name = line[1]
        filename_out = DIR + 'extract\\' + line_name + station_name + '.txt'
        file_out = open(filename_out, 'w')
        file.readline()
        n=int(file.readline().strip().split()[1])	# number of frequencies recorded for the station
        file.readline()
        for i in range(n):
            line_data=file.readline()
            file_out.write(line_data)
        file_out.close()
        line=file.readline()
    file.close()

solved: redundancies in the source files were creating these problems, data were written correctly, then overwritten with zeros. couldn't see it unless debug mode was active.

This question has already been answered. Start a new discussion instead.