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 'w' if chosen to overwrite.
- When 'lab.csv' is created, find lines in 'lab.txt' that begin with:
- "From:" - email extract (for example, ONLY 'louis@media.berkeley.edu')
- "Subject:" - number extract (for example, ONLY 'r39757')
- "X-DSPAM-Confidence:" value extract (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!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started