简体   繁体   English

我如何 go 关于在循环中读取 csv 文件

[英]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.

相关问题 如何从该网站自动获取一个csv文件? - How do I go about automatically grabbing a csv file from this website? 如何在同一个“for”循环中转到CSV文件的第一个记录? - How do I go to the first record of a CSV file within the same “for” loop? 如何在.csv文件中分离数据? - How to go about separating data in a .csv file? 在for循环中读取csv文件时出现意外输出 - Unexpected output while reading a csv file in a for loop 如何在Django中流式传输音频文件? - How do I go about streaming an audio file in Django? 在使用Python读取CSV文件时,如何转义逗号? - How do I escape commas while reading CSV files with Python? 如何在读取 Python 中的文件行时不创建无限循环? - How do I not create an infinite loop while reading file lines in Python? 我将如何将 .csv 转换为 .arrow 文件而不将其全部加载到内存中? - How would I go about converting a .csv to an .arrow file without loading it all into memory? 从csv文件读取输入时,如何在将数据插入Cassandra中时达到50k / sec的吞吐量? - How do I achieve the throughput of 50k/sec in inserting my data in Cassandra while reading input from a csv file? 我将如何阅读bittorrent片段? - How would I go about reading bittorrent pieces?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM