A Python program that reads a file, adds line numbers, converts to uppercase, and writes to a new file.
- 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
├── 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
python file_processor.py
- Enter filename when prompted
- Content is processed automatically (line numbers + uppercase)
- New file created with "_modified" suffix
- Enter 'quit' or 'q' to exit
python test_processor.py
Runs automated tests to verify functionality.
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!
Edit config.py
to customize:
- File encoding
- Output file suffix
- Line number formatting
- User interface messages
Try these scenarios:
sample_text.txt
(valid file)- Non-existent file (error handling)
- Empty input or 'quit' to exit
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