Answered step by step
Verified Expert Solution
Question
1 Approved Answer
My code writes emails to a text file, but I need them to be listed in the text file like so: a@abc.com b@abc.com c@abc.com In
My code writes emails to a text file, but I need them to be listed in the text file like so:
a@abc.com
b@abc.com
c@abc.com
In other words, I need them in one vertical column, a new line after each email, written to the text file.
How could i do this?
My code is:
import re f = open("wos.txt", "r") ff = (f.read()) #print(ff) f.close() email_pattern = re.compile(r'[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}') # define an email pattern text = ff a = email_pattern.findall(ff) length_list = [len(element) for row in a for element in row] column_width = max(length_list) for row in a: row = "".join(element.ljust(column_width) for element in row) print(row) b = row #print(email_pattern.findall(ff), items) g = open("output.txt", "w") g.write(" ".join(a)) g.close() #close the file
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started