Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function to read the list of email addresses from a file. Each line of t

ID: 3573189 • Letter: W

Question

Write a function to read the list of email addresses from a file. Each line of the file contains a single email address with user and host separated by an at sign('@') character. The function will be given the filename and will return a list of lists. Each element of the list is a list with two values: user name (string) and host name (string). You must parse each line, partition into parts, and string white space from each entry. You must handle when the file does not exist and return an empty list. (Hint: use try-except for exception handling)

Use the following function definition

def myBuild(filename):

Explanation / Answer

fname = 'emails.txt'
def myBuild(filename):
    try:
        with open(fname) as f:
            content = f.readlines()
        emails = []
        for line in content:
            data = line.split("@")
            data[1] = data[1][:-1]
            emails.append(data)
        return emails
    except IOError:
        print "File not present."

print myBuild(fname)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote