This repository contains two Python programs designed to demonstrate file handling and exception handling concepts. These programs fulfill the requirements of the assignment by performing file operations and gracefully managing errors.
This assignment focuses on:
- Efficiently managing files using Python's file handling techniques.
- Handling unexpected issues gracefully using exception handling.
By the end of this project, you will have a solid understanding of how to:
- Read from and write to files.
- Handle errors such as missing files or inaccessible files.
- Create robust and user-friendly applications.
This program reads the content of a file, processes it, and writes a modified version to a new file. Specifically:
- Reads the content of
input.txt. - Converts the content to uppercase.
- Writes the modified text and additional information (e.g., word count) to
output.txt.
- Demonstrates file reading and writing.
- Modifies the content as part of the task.
- Ensures proper use of context managers for file operations.
This program asks the user for a filename and handles potential errors gracefully. It includes:
- Checking if the file exists.
- Handling errors if the file cannot be read.
- Displaying meaningful error messages to the user.
- Demonstrates exception handling in Python.
- Provides a user-friendly interface for error messages.
- Ensures robust and error-free execution.
By completing this assignment, I have:
- Gained experience in managing files with Python.
- Understood how to handle common file-related errors.
- Learned to write clean, efficient, and user-friendly code.
- Python 3.x installed on your system.
-
Clone this repository:
git clone https://github.com/OneWilly/File-Handling-and-Exception-Handling-Assignment.git cd File-Handling-and-Exception-Handling-Assignment -
Run the
file_read_write.pyscript:- Ensure you have an
input.txtfile in the same directory with some sample content. - Run the script:
python3 file_read_write.py
- Check the
output.txtfile for the modified content.
- Ensure you have an
-
Run the
error_handling_lab.pyscript:- Run the script:
python3 error_handling_lab.py
- Enter the name of a file when prompted. Test with existing and non-existing files to see how errors are handled.
- Run the script:
file_read_write.py: Script for the File Read & Write Challenge.error_handling_lab.py: Script for the Error Handling Lab.README.md: Documentation for the assignment.input.txt: Sample input file for testingfile_read_write.py.output.txt: Output file generated byfile_read_write.py.
This project is licensed under the MIT License. See the LICENSE file for details.