I am trying to read multiple text files in a folder to plot a specific column(last column) of each of the file. I have used the following code to do that:
file_library = os.listdir(path)
for book in file_library:
file = os.path.join(path, book)
if file.endswith(".txt"):
f = open(file, "r")
for line in f:
reads = read_ydata(f)
print reads
f.close()
where read_ydata function is defined as follows:
y_values = []
line = filename.readline()
while line != '':
y_val = line[line.rfind(' ') + 1:]
y_values.append(float(y_val))
line = filename.readline()
return y_values
Now when i run this i get an error: ValueError: Mixing iteration and read methods would lose data and if i replace it with next() i get the error: StopIteration.
Plz advice as to how to get rid of these errors or to implement my logic..