"# week4python"
This Python program demonstrates how to read from a file, modify its contents, and write the result to a new file while handling errors gracefully.
-
Reads text from a user-specified file.
-
Converts the content to uppercase (as an example of modification).
-
Writes the modified text to a new file prefixed with
modified_
. -
Handles common errors such as:
- File not found
- Permission issues
- Unexpected errors
- Save the script as
file_handler.py
. - Open your terminal and run:
python file_handler.py
- Enter the name of the file you want to read.
- If the file exists, a new file (e.g.,
modified_example.txt
) will be created with the modified content.
Input file (example.txt
):
Hello world!
Python is fun.
Output file (modified_example.txt
):
HELLO WORLD!
PYTHON IS FUN.
- File input/output (I/O) in Python
- Exception handling (
try/except
) - Building robust, error-proof programs