Skip to content

J-Njoroge/week4python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 

Repository files navigation

"# week4python"


πŸ“‚ File Read & Write with Error Handling

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.


Features

  • 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

How to Run

  1. Save the script as file_handler.py.
  2. Open your terminal and run:
python file_handler.py
  1. Enter the name of the file you want to read.
  2. If the file exists, a new file (e.g., modified_example.txt) will be created with the modified content.

Example

Input file (example.txt):

Hello world!
Python is fun.

Output file (modified_example.txt):

HELLO WORLD!
PYTHON IS FUN.

Skills Practiced

  • File input/output (I/O) in Python
  • Exception handling (try/except)
  • Building robust, error-proof programs

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages