Reputation: 33655
I have a CSV which I load...
import csv
file = upload.filepath
file_read = csv.reader(file)
data = [row for row in file_read]
In my template I want to list each item without having to know the name....
I think what I need is to count how many items are in the row, loop that amount of times getting each item? maybe?
So my output could be
myemail,mynumber,[email protected],1
myemail2,mynumber2,[email protected],2
Or even
myname,0897654543
myname,0897654w543
either way I never know how many columns are in the csv
Update:
So could I just do this?
{% for item in data %}
{% for i in item %}
{{ i }}
{% endfor %}
{% endfor %}
Upvotes: 0
Views: 81
Reputation: 31090
Could you use numpy.genfromtxt
?
import numpy as np
data = np.genfromtxt("yourfile.csv",delimiter=",")
This will make data
a numpy array with as many columns as are in your csv file..
Upvotes: 2
Reputation: 20226
I don't understand what you mean by "In my template I want to list each item". But if you just want to print out each row, you can do
for row in file_read :
print row
or to print each item individually,
for row in file_read :
for item in row :
print item
Upvotes: 1