I have two simple csv files: test_1 and test_2. test_1 contains the following:
Letters
A
B
C
D
while test_2 contains:
Numbers
1
2
3
4
I used the following code:
import parsecsv
var p,q: CsvParser
p.open("test_1.csv")
q.open("test_2.csv")
p.readHeaderRow()
q.readHeaderRow()
while q.readRow():
while p.readRow():
echo p.rowEntry("Letters")
I expected the output to be the 4 letters repeated four times but what I got was only
A
B
C
D
What could be the explanation for this?You can add echo statements to your source code to see what happens:
import parsecsv
var p,q: CsvParser
p.open("test_1.csv")
q.open("test_2.csv")
p.readHeaderRow()
q.readHeaderRow()
while q.readRow():
echo "while q.readRow():"
while p.readRow():
echo p.rowEntry("Letters")
$ ./t2
while q.readRow():
A
B
C
D
while q.readRow():
while q.readRow():
while q.readRow():
I did that as I never used parsecsv before, so guessing may be not easy for me. With echo it is obvious: p.readRow() does its work, for each line, then is at the end of the file and does nothing any more. You may consult API docs if you can reset it to read from beginning again.