Question: 1. Make a folder called 'binder' and place 'lab.txt' in it. ('lab.txt' is https://www.py4e.com/code3/mbox.txt) 2. Create a Python program to: - Ask for user input

1. Make a folder called 'binder' and place 'lab.txt' in it. ('lab.txt' is https://www.py4e.com/code3/mbox.txt)

2. Create a Python program to:

- Ask for user input for the file name (for a file that's missing, use exceptions)

- When the proper file name is given, open an output file named 'lab.csv' and store it in 'binder'. Use os.path to check if a file already exists in the folder. If it already exists, prompt the user to either overwrite it or create a different output file. Use 'y/n' for user input and 'w' if chosen to overwrite.

- When 'lab.csv' is created, find lines in 'lab.txt' that begin with:

- "From:" - email extract (for example, louis@media.berkeley.edu)

- "Subject:" - number extract (for example, r39757)

- "X-DSPAM-Confidence:" value extract (for example, 0.6932)

- Place these results in 'lab.csv' for EVERY time one of these shown above and give them headers of 'Email', 'Subject', and 'Value'

- When the data has been transferred to 'lab.csv', print 'The data has been successfully stored!' and finish the program

3. Note:

- When getting the file name, strip input and do not lower

- Use functions if you want

SAMPLE OUTPUT

Please input the file: new.txt

That file does not exist.

Please input the file: lab

That file does not exist.

Please input the file: lab.txt

Please state the output: lab.csv

File already exists. Overwrite (y/n)?: z

Please enter (y/n): b

Please enter (y/n): N

What is the new output: lab.csv

File already exists. Overwrite (y/n)?: n

What is the new output: new.csv

The data has been successfully stored!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!