Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions