I have a single text file with several lines of information with three items separated by commas. An example of a few lines:
name1, email1, password1
name2, email2, password2
name3, email3, password3
Using:
the program prints a list similar to:
['name1, email1, password1\n', 'name2, email2, password2\n', 'name3, email3, password3\n']
A list delimited by the new line character?
My question is: how can I read in this text file with the same format but instead, make a list where each element is delimited by the comma between each word and the new line at the end of each line.
Also is there are way to pass this into a dictionary instead of a list, using 3 keys ("name" "email" "password") and the corresponding values in the text file?
name1, email1, password1
name2, email2, password2
name3, email3, password3
Using:
Code:
def main():
f = open("database.txt","r")
print f.readlines()
main()
['name1, email1, password1\n', 'name2, email2, password2\n', 'name3, email3, password3\n']
A list delimited by the new line character?
My question is: how can I read in this text file with the same format but instead, make a list where each element is delimited by the comma between each word and the new line at the end of each line.
Also is there are way to pass this into a dictionary instead of a list, using 3 keys ("name" "email" "password") and the corresponding values in the text file?
Comment