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 (lab.txt) For a file that's missing, use exceptions.
- When the proper file name is given 'lab.txt', open an output file named 'lab.csv' and store it in the folder 'binder'. Use os.path to check if the output 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 use 'w' if chosen to overwrite.
- When 'lab.csv' is created, write code to find lines in 'lab.txt' that begin with:
- "From:" - extract the email (for example, ONLY 'louis@media.berkeley.edu')
- "Subject:" - extract the number (for example, ONLY 'r39757')
- "X-DSPAM-Confidence:" extract the value (for example, ONLY '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 user input for 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.txt
Please state the output: lab.csv
The data has been successfully stored!
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!
PLEASE DO NOT ANSWER IF YOUR PROGRAM DOES NOT WORK LIKE THE SAMPLE OUTPUTS SHOWN ABOVE. ENSURE THAT THE OUTPUT DOES INCLUDE ALL THE VALUES (EMAIL, SUBJECT, VALUE)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
