Skip to content

OneWilly/File-Handling-and-Exception-Handling-Assignment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

File Handling and Exception Handling Assignment

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.

Table of Contents


Description

This assignment focuses on:

  1. Efficiently managing files using Python's file handling techniques.
  2. 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.

Programs

File Read & Write Challenge

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.

Key Features:

  • Demonstrates file reading and writing.
  • Modifies the content as part of the task.
  • Ensures proper use of context managers for file operations.

Error Handling Lab

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.

Key Features:

  • Demonstrates exception handling in Python.
  • Provides a user-friendly interface for error messages.
  • Ensures robust and error-free execution.

Outcomes

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.

How to Run

Prerequisites:

  • Python 3.x installed on your system.

Steps:

  1. Clone this repository:

    git clone https://github.com/OneWilly/File-Handling-and-Exception-Handling-Assignment.git
    cd File-Handling-and-Exception-Handling-Assignment
  2. Run the file_read_write.py script:

    • Ensure you have an input.txt file in the same directory with some sample content.
    • Run the script:
      python3 file_read_write.py
    • Check the output.txt file for the modified content.
  3. Run the error_handling_lab.py script:

    • 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.

Repository Structure

  • 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 testing file_read_write.py.
  • output.txt: Output file generated by file_read_write.py.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages