I have a csv file that looks like this:
name1, id1, email1, uID1
name2, id2, email2, uID2
name3, id3, email3, uID3
name4, id4, email4, uID4
name5, id5, email5, uID5
name6, id6, email6, uID6
And I want to grab a random email from this. For ex. I want email4 and only email4. How do I read that in? I don't want name4 id4 and uID4 with it, Just email4.
Note: I am writing a method to do this and want to return email4 not print it.
I have seen lots of info on how to get an entire row or an entire column, but not how to get one piece of a row. How do I do this?
I have looked through and tried all options on this thread: How can I get a specific field of a csv file? But the answers were not working for me. So new solutions or fixes to their solutions would be great!
Here is where I am currently at now:
num = random.randint(1,11)
with open('Accounts_details.csv', 'rb') as f:
reader = csv.reader(f)
reader = list(reader)
text = reader[num][2]
print(text)
And this throws an error:
reader = list(reader)
_csv.Error: iterator should return strings, not bytes (did you open the file in text mode?)