I've created a text file that just has an unformatted list of emails, all on a new line. Ex:
This is the unformatted list called emailListTest.txt
a@a.org
b@b.org
c@c.org
d@d.org
e@e.org
f@f.org
g@g.org
h@h.org
I have another app that opens and reads the unformatted email list file. Then it creates a new python file and tries to put the unformatted list of emails all in a python list.
This all started because I wanted to learn how to send emails with code. I've made another app that does this, but I wanted one that sends emails to multiple people at the same time.
This is my writer app
emailListFile = open("emailListTest.txt", "r")
emailListFileList = open("emailListTestList.py","w")
print(emailListFileList.write("emailAsList = "))
print(emailListFileList.write("["))
def emailAddressList():
#try:
for i in emailListFile:
print(emailListFileList.write( "\n'" + i + "'" + ", "))
emailAddressList()
print(emailListFileList.write("]"))
emailListFile.close()
emailListFileList.close()
I must be missing something because the output is
emailAsList = [
'a@a.org
',
'b@b.org
',
'c@c.org
',
'd@d.org
',
'e@e.org
',
'f@f.org
',
'g@g.org
',
'h@h.org', ]
I feel like it's so close to being right, if only there weren't these new lines from the unformatted list file splitting the ', onto a new line.
If anyone knows how to solve my issue, I'd greatly appreciate it! (Also, if anyone has any other tips to simplify other parts in my code, I'd love to know. I'm still learning!)
Thank you!
source https://stackoverflow.com/questions/75584456/how-do-i-turn-an-unformatted-text-file-list-into-a-python-list-in-another-file
Comments
Post a Comment