Skip to content

Langat1999/PythonWK4

Repository files navigation

Simple File Processor

A Python program that reads a file, adds line numbers, converts to uppercase, and writes to a new file.

Features

  • Read text files with error handling
  • Add line numbers and convert to uppercase
  • Write modified content to new file
  • Simple command-line interface
  • Clean, minimal output
  • Configurable settings
  • Comprehensive error handling

Project Structure

├── file_processor.py    # Main program
├── config.py            # Configuration constants
├── test_processor.py    # Test script
├── sample_text.txt      # Sample input file
├── requirements.txt     # Dependencies
└── README.md           # This file

Usage

Main Program

python file_processor.py
  1. Enter filename when prompted
  2. Content is processed automatically (line numbers + uppercase)
  3. New file created with "_modified" suffix
  4. Enter 'quit' or 'q' to exit

Test Script

python test_processor.py

Runs automated tests to verify functionality.

Example

File Processor
====================

Enter filename (or 'quit' to exit): sample_text.txt
Successfully processed 'sample_text.txt' -> 'sample_text_modified.txt'

Enter filename (or 'quit' to exit): quit
Goodbye!

Configuration

Edit config.py to customize:

  • File encoding
  • Output file suffix
  • Line number formatting
  • User interface messages

Testing

Try these scenarios:

  • sample_text.txt (valid file)
  • Non-existent file (error handling)
  • Empty input or 'quit' to exit

Learning

Demonstrates:

  • File I/O operations with encoding
  • Error handling with try-catch
  • List comprehensions
  • Function design and separation of concerns
  • Configuration management
  • Clean user interface design
  • Modular code structure

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages