我有这样的功能:如何在Python中通过此列表循环访问用户名和密码?
import csv
def total():
with open('test.csv', 'r') as csvfile:
spamreader = csv.reader(csvfile)
a = [row for row in spamreader]
return a
print total()
的输出是:
[['[email protected]', '1234'], ['[email protected]', 'metal'], ['[email protected]', 'hello']]
我想遍历每个用户名和密码,直到列表的末尾。目的是我想逐个传递用户名和密码。 首先,我想使用[email protected]和1234,然后进入另一个。
我试着使用:
def pass_username():
with open('test.csv', 'r') as csvfile:
spamreader = csv.reader(csvfile, delimiter=',')
a = [row[0] for row in spamreader]
return a
def pass_password():
with open('test.csv', 'r') as csvfile:
spamreader = csv.reader(csvfile, delimiter=',')
a = [row[1] for row in spamreader]
return a
但是,这一次返回的用户名,在一次和密码这样的:
[email protected]
[email protected]
[email protected]
1234
metal
hello
我该如何解决这个问题?由于
你已经有了你需要的第一个功能。你对什么感到困惑? – asheeshr
请在我的回答中看到我的评论。 – user1881957