[英]how to create a loop to read line by line from a csv file
good night friends, i'm new to python and i need help to create a loop to read line by line from a csv file, any ideas?朋友们晚安,我是 python 新手,我需要帮助来创建一个循环来从 csv 文件中逐行读取,有什么想法吗?
my code :我的代码:
file = csv.reader(open('amino_acids.csv'), delimiter = ';')
next(file)
for [Link, Titulo, DSNStockCod, SKU, DIMENSIONS, Weight, Price, Description, Directions, Warnings, Url_Imagem] in arquivo:
print (str(Titulo))
Where is "arquivo" coming from? “arquivo”从何而来? I think you need to start reading the file like this:
我认为您需要像这样开始阅读文件:
for line in file:
Inside that loop, you can write code to accomplish whatever it is you're trying to do.在该循环中,您可以编写代码来完成您想要做的任何事情。 I am a little bit confused because your file suggests it contains amino acid data, but the list in your for loop is seemingly unrelated.
我有点困惑,因为您的文件表明它包含氨基酸数据,但您的 for 循环中的列表似乎无关。
Convert each row to a tuple then deconstruct to variables.将每一行转换为元组,然后解构为变量。
file = csv.reader(open('amino_acids.csv'), delimiter = ';')
for row in file:
Link, Titulo, DSNStockCod, SKU, DIMENSIONS, Weight, Price, Description, Directions, Warnings, Url_Imagem = tuple(row)
print (str(Titulo))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.