Python: How to restart a FOR loop, which iterates over a csv
<p>I am using Python 3.5 and I wanna load data from a csv into several lists, but it only works exactly one time with a FOR-Loop. Then it loads 0 into it.</p>

<p>Here is the code:</p>

<pre><code>f1 = open("csvfile.csv", encoding="latin-1")
csv_f1 = csv.reader(f1, delimiter=';')

list_f1_vorname = []
for row_f1 in csv_f1:
    list_f1_vorname.append(row_f1[2])

list_f1_name = []
for row_f1 in csv_f1:   # &lt;-- HERE IS THE ERROR, IT DOESNT WORK A SECOND TIME!
    list_f1_name.append(row_f1[3])    
</code></pre>

<p>Does anybody know how to restart this thing?
Many thanks and best regards,
Saitam</p>

<p><code>csv_f1</code> is not an <code>list</code>, it is an iterative.</p>

<p>Either, you cache the <code>csv_f1</code> into a list by using <code>list()</code> or you just recreate the object.</p>

<p>I would recommend to recreate the object in case your cvs data gets very big. This way, the data is not put into RAM completely.</p>

python loops csv for-loop restart