I have a simple function to read the csv file and extracts the first coloum from it:
import csv
def pass_username():
with open('test.csv', 'r') as csvfile:
spamreader = csv.reader(csvfile, delimiter=',')
for row in spamreader:
return row[0]
When I call this function as:
a = pass_username()
print a
This only prints the first element. However, when I replace return
word with print
as print row[0]
and call the function as pass_username()
it prints all the elements. I want to assign that function to a variable thus I want to use return. How to fix it?
Content of test.csv:
"test@gmail.com","rockon"
"hello@gmail.com","hey"
"hithere@gmail.com","ok"
"hellosir@gmail.com","password"