我有这样的功能:
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()
的输出是:
[['admin@gmail.com', '1234'], ['ok@gmail.com', 'metal'], ['hithere@gmail.com', 'hello']]
我想遍历每个用户名和密码,直到列表结束。目的是我想将用户名和密码一一传递。首先,我想使用 admin@gmail.com 和 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
但这会立即返回用户名和密码,如下所示:
admin@gmail.com
ok@gmail.com
hihere@gmail.com
1234
metal
hello
我怎样才能解决这个问题?谢谢