I have a function like this:
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()
The output of is:
[['admin@gmail.com', '1234'], ['ok@gmail.com', 'metal'], ['hithere@gmail.com', 'hello']]
I want to loop over each username and password until the end of list. The purpose is I want to pass the username and password one by one.
First I want to use admin@gmail.com and 1234 and then proceed to another.
I tried using:
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
But this returns username at once and password at once like this:
admin@gmail.com
ok@gmail.com
hihere@gmail.com
1234
metal
hello
How can I fix this? Thanks
Change this to a single function :
This will return a list of 2d tuples containing username, password.
You can simply do this from your first function as well, by using a for loop after that. The only change i suggest is using tuples instead of lists, to make the data immutable.