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 "[email protected]" OR "[email protected]", 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:
```
[email protected]
[email protected]
[email protected]
[email protected]
```
should result in the following printed to the screen:
```
[email protected] Deer, Doe ray.me
[email protected] Robot, I. sneaker.net
[email protected] Sew, Far ray.me
[email protected] 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 [email protected]. 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

[email protected] Smith,A boring.com
[email protected] Witcher,A coldasheck.net
[email protected] Demarcus,Johnson semper.org
[email protected] Shelly,Baker supplyshack.com
[email protected] Parker,P spider.org
[email protected] Meghan,Markle royals.gov
[email protected] Seedy,Mcshady criminal.inc
[email protected] Bird,B sesame.st
[email protected] Cunningham12,D rasa.net
[email protected] Harry,Potter hogwarts.edu
[email protected] Gekko,G capital.com
[email protected] Paul,York augusta.edu
[email protected] Weldon,S augusta.edu
The total emails:13
The count of unique domain names:12

emails.txt

[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]

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....

  • 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...

  • Python 3.7 Coding assignment This Program should first tell users that this is a word analysis...

    Python 3.7 Coding assignment This Program should first tell users that this is a word analysis software. For any user-given text file, the program will read, analyze, and write each word with the line numbers where the word is found in an output file. A word may appear in multiple lines. A word shows more than once at a line, the line number will be only recorded one time. Ask a user to enter the name of a text file....

  • PYTHON CODE ONLY PLEASE, AND COMMENT IN SCRIPT TO SHOW STEPS (post copy-ready text code, and also...

    PYTHON CODE ONLY PLEASE, AND COMMENT IN SCRIPT TO SHOW STEPS (post copy-ready text code, and also a screenshot of code running) You work for an on-line game site. Your job is to develop a program that accepts a user name and password. Write a Python script that prompts users for a user name and password. a. The user name should be at least 6 characters long and is stored in a list such that it 1. can't be used...

  • 1. Create a Python script file called Assignment_Ch06-02_yourLastName.py. (Replace yourLastName with your last name.) 2. Write...

    1. Create a Python script file called Assignment_Ch06-02_yourLastName.py. (Replace yourLastName with your last name.) 2. Write a Python program that prompts the user for a sentence, then replaces all the vowels in the sentence with an asterisk: '*' Your program should use/call your isVowel function from Assignment_Ch06-01. You can put the isVowel() function in a separate .py file, without the rest of the Ch06-01 code, and then import it. 6-01 CODE: def isVowel(x):     if x in "aeiouyAEIOUY":         return True     else:...

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
ADVERTISEMENT