Question

Python Coding The script, `eparser.py`, should: 1. Open the file specified as the first argument to...

Python Coding

The script, `eparser.py`, should:

1. Open the file specified as the first argument to the script (see below)
2. Read the file one line at a time (i.e., for line in file--each line will be a separate email address)
3. Print (to the screen) a line that "interprets" the email address as described below
4. When finished, display the total number of email addresses and a count unique domain names

Each email address will either be in the form "first.last@domain.ext" OR "ilast@domain.ext", where "first" and "last" are the first and last names of the person respectively, and "i" is the first initial. Each "line" (step 4) should contain the email address itself, the name (either "Last, First" or "Last, I." where "I" is the first initial, and the domain name of th email address. The name components should be in "title case" (capitalize first letter of all words/initials). So for example, the following two email addresses in the input file:
```
doe.deer@ray.me
irobot@sneaker.net
far.sew@ray.me
ltea@ray.me
```
should result in the following printed to the screen:
```
doe.deer@ray.me Deer, Doe ray.me
irobot@sneaker.net Robot, I. sneaker.net
far.sew@ray.me Sew, Far ray.me
ltea@ray.me Tea, L. ray.me
Number of Addresses: 4
Unique Domain Names: 2
```
Allow 35 characters for the email address, 25 characters for the full name and 20 characters for the domain name for a total of 80 characters wide per line of output. All fields should be left aligned (that's the default for strings).

## HINTS

1. The "arguments" to a python program are in the sys.argv list. The first element in the list is the name of the script and the rest are any additional words (arguments) added to the end. [See here for explanation](https://www.tutorialspoint.com/python/python_command_line_arguments.htm). The code needed may look as follows:
```
import sys

filename = sys.argv[1]
```

## REQUIRED IMPLEMENTATION NOTES

1. You MUST abstract your most useful logic by creating a function named `parse_address` that takes an email address as a parameter and prints the line formatted as described above. This function should be "called" as your step 3 above, which will make the main script much cleaner. So to reiterate, the following function MUST be in your code:
```
def parse_address(email):
... DO STUFF HERE ...
```
2. You MUST use either the format() function or an f-string to format your lines of text. In other words, you __cannot__ use the center(), ljust() and rjust() methods. Those methods are okay, but don't use them here.

3. You MUST modify emails.txt, and add your own email address at the bottom as first.last@augusta.edu. JUST edit and save the file using VS code or another text editor. No Python code required here.

4. You MUST run your script against the file `emails.txt` and redirect the output to `contacts.txt`. In other words, you should run `python eparser.py emails.txt > contacts.txt`. This file should be in your final submission.

contacts.txt

asmith@boring.com Smith,A boring.com
awitcher@coldasheck.net Witcher,A coldasheck.net
demarcus.johnson@semper.org Demarcus,Johnson semper.org
shelly.baker@supplyshack.com Shelly,Baker supplyshack.com
pparker@spider.org Parker,P spider.org
meghan.markle@royals.gov Meghan,Markle royals.gov
seedy.mcshady@criminal.inc Seedy,Mcshady criminal.inc
bbird@sesame.st Bird,B sesame.st
dcunningham12@rasa.net Cunningham12,D rasa.net
harry.potter@hogwarts.edu Harry,Potter hogwarts.edu
ggekko@capital.com Gekko,G capital.com
paul.york@augusta.edu Paul,York augusta.edu
sweldon@augusta.edu Weldon,S augusta.edu
The total emails:13
The count of unique domain names:12

emails.txt

asmith@boring.com
awitcher@coldasheck.net
demarcus.johnson@semper.org
shelly.baker@supplyshack.com
pparker@spider.org
meghan.markle@royals.gov
seedy.mcshady@criminal.inc
bbird@sesame.st
dcunningham12@rasa.net
harry.potter@hogwarts.edu
ggekko@capital.com
paul.york@augusta.edu
sweldon@augusta.edu

0 0
Add a comment Improve this question Transcribed image text
Answer #1

out=open("contacts.txt","w")#open output file in write mode
domain_list=[]
def parse_address(email):#method that parses addresses
temp=[]
temp=email.split("@")#split string by @
if '.' in temp[0]:
out.write(l[i]+" "+temp[0].split('.')[0].title()+","+temp[0].split('.')[1].title()+" "+temp[1]+"\n")#write to output file
domain_list.append(temp[1])#get domain and append to list
else:
out.write(l[i]+" "+temp[0][1:].title()+","+temp[0][0].title()+" "+temp[1]+"\n")#write to output file
domain_list.append(temp[1])
  
f=open("emails.txt","r")#open file in read mode
l=f.readlines()
for i in range(len(l)):
l[i]=l[i][:-1]
total_emails=0
domain_names_count=0

for i in range(len(l)):#for each email, call method
parse_address(l[i])


domain_set=list(set(domain_list))
print("The total emails:"+str(len(l)))#print details on console and write to output file.
print("The count of unique domain names:"+str(len(domain_set)))
out.write("The total emails:"+str(len(l))+"\n")
out.write("The count of unique domain names:"+str(len(domain_set))+"\n")
out.close()

Screenshots:

The Screenshots are attached below for reference.

Please follow them for proper indentation.

Please upvote my answer.

Thank you.

Add a comment
Know the answer?
Add Answer to:
Python Coding The script, `eparser.py`, should: 1. Open the file specified as the first argument to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The first script is validate.sh. This is a simple form validation script that will be used...

    The first script is validate.sh. This is a simple form validation script that will be used to verify the inputs given. Normally, this would be done to validate input from a website or another program before entry into a database or other record storage. In this case, we will keep it simple and only focus on the input validation step. In particular, the script should prompt the user for four values: first name, last name, zip code, and email address....

  • The first script is validate.sh. This is a simple form validation script that will be used...

    The first script is validate.sh. This is a simple form validation script that will be used to verify the inputs given. Normally, this would be done to validate input from a website or another program before entry into a database or other record storage. In this case, we will keep it simple and only focus on the input validation step. In particular, the script should prompt the user for four values: first name, last name, zip code, and email address....

  • please use Python You are to create a program that generates an email addresses. The format...

    please use Python You are to create a program that generates an email addresses. The format is as follows: firstname.lastname@domain.topleveldomain (maximum 60 characters) example (aaa.bbb@ccc.ddd) please use any number of variables and types that you wish. The only requirement is that you ask the user one at a time for first name, last name, domain and TLD (top level domain), use that to generate the email address string. The maximum size of the created email address string is 60. If...

  • Using C(89). A fashion retailer has decided to provide discount codes to teachers and students during...

    Using C(89). A fashion retailer has decided to provide discount codes to teachers and students during a promotional event. The first step is to verify the teacher/student status of people requesting discount code by their email addresses. They will check if the email addresses end with ".edu" and find the domain name if it does before further verification. Write a program to find the domain name of an email address if the domain name ends with .edu. The program displays...

  • For Python | Instructions Write a script named difpy. This script should prompt the user for...

    For Python | Instructions Write a script named difpy. This script should prompt the user for the names of two text files and compare the contents of the two files to see if they are the same. 1. If they are the script should simply output "Yes". 2. If they are not the script should output "No", followed by the first lines of each file that differ from each other The input loop should read and compare lines from each...

  • Java2 Screenshot of the output required Put some comment This is the mailing text file for...

    Java2 Screenshot of the output required Put some comment This is the mailing text file for the assignment ..Il AT&T令 12:28 AM Back Complete and Submit Lab 2C Detail Submission Grade Complete and Submit Lab 2C Due: Mar 1, 2019 at 11:59 PM In class you learned how to read text from a file using the Scanner class and write text to a file using the Formatter class. This lab allows you to apply the skills you learned about files...

  • Write a program in C++: Using classes, design an online address book to keep track of the names f...

    Write a program in C++: Using classes, design an online address book to keep track of the names first and last, addresses, phone numbers, and dates of birth. The menu driven program should perform the following operations: Load the data into the address book from a file Write the data in the address book to a file Search for a person by last name or phone number (one function to do both) Add a new entry to the address book...

  • (IN PYTHON) You are to develop a Python program that will read the file Grades-1.txt that...

    (IN PYTHON) You are to develop a Python program that will read the file Grades-1.txt that you have been provided on Canvas. That file has a name and 3 grades on each line. You are to ask the user for the name of the file and how many grades there are per line. In this case, it is 3 but your program should work if the files was changed to have more or fewer grades per line. The name and...

  • Write a Python program to create userids: You work for a small company that keeps the...

    Write a Python program to create userids: You work for a small company that keeps the following information about its clients: • first name • last name • a user code assigned by your company. The information is stored in a file clients.txt with the information for each client on one line (last name first), with commas between the parts. In the clients.txt file is: Jones, Sally,00345 Lin,Nenya,00548 Fule,A,00000 Your job is to create a program assign usernames for a...

  • The python code required is for a text file that has names and numbers associated with...

    The python code required is for a text file that has names and numbers associated with those names e.g.( GARCIA   0.31817:) infile = open('last.txt', 'r') - the file must be read only for line in infile: the question is this: Find the longest last name and assign it to “ans14” variable.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT