[英]How do I go about reading a csv file while in a loop
Hey so Im trying to make it so my code basically reads through a csv file like this.嘿,所以我试图做到这一点,所以我的代码基本上是通过这样的 csv 文件读取的。
gmail,password
Jamesz73an6@test.com,James9123
Ryan@test.com,Ryan9123
I want to try to make it so when it reads the first line in the loop, when it is ran again (if the user decides to run 2 tasks) it will go to the next line.我想尝试这样做,因此当它读取循环中的第一行时,当它再次运行时(如果用户决定运行 2 个任务),它将 go 到下一行。 My current code is like this.我现在的代码是这样的。
taskCount = int(input('How many accounts would you like to warm? '))
for i in range(taskCount):
with open ('nikeaccounts.csv') as csvfile:
reader = csv.DictReader(csvfile)
for row[taskCount] in reader:
print('')
login = (row['gmail'])
password = (row['password'])
The code below prints the login and the password for each extracted line, but you can just as easily save them in a list for future use:下面的代码打印每个提取行的登录名和密码,但您可以轻松地将它们保存在列表中以供将来使用:
import csv
taskCount = int(input('How many accounts would you like to warm? '))
with open('contact_list.csv', 'r') as data:
reader = list(csv.reader(data))
for i in range(1, taskCount+1):
print(f'login: {reader[i][0]}, password: {reader[i][1]}')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.