Got absolutely bored and carried away with a course project... accidentally turned it into a whole thing :)
A modular Python application that demonstrates separation of concerns across sorting, I/O, networking, and orchestration layers.
-
Sorting Module (
sorting.py)- Implements core business logic (
sort_data()). - Provides utility functions:
sort_data_inplace(),is_sorted(), and built-in self-tests. - Handles mixed data types by converting non-comparable elements into strings.
- Implements core business logic (
-
I/O Module (
io_handler.py)- Abstracts console and file operations.
- Functions:
read_keyboard_input(),write_screen_output(),read_file_input(),write_file_output(). parse_input()detects integers, floats, and strings automatically.
-
Networking Module (
network_handler.py)- Provides
NetworkServerandNetworkClientclasses. - Supports TCP communication with customizable handlers.
- Includes
create_sorting_handler()to bridge sorting logic with network requests.
- Provides
-
Main Orchestrator (
main.py)- Command-line entry point.
- Routes execution to the correct module based on CLI arguments.
- Demonstrates clean separation between orchestration and core logic.
Run the following command to display usage information:
python3 main.py- A Python 3.8+ version. To check your current version, execute the following command:
python3 --versionInteractive sorting directly from the terminal.
python3 main.py keyboardRead input from a file and write sorted output to another file (or display on screen if no output file is provided).
python3 main.py file <input_file> [output_file]Sort a file and overwrite it with the sorted content.
python3 main.py file_inplace <filename>Start a TCP server that listens for sorting requests.
python3 main.py server [port] Connect to a server and send data for sorting.
python3 main.py client "<data>" [host] [port]Run built-in tests for all modules.
python3 main.py testpython3 sorting.py # Test sorting module
python3 io_handler.py # Test I/O module
python3 network_handler.py # Test network moduleIf you run the network_handler.py module directly without starting the server first:
$ python3 network_handler.py
Testing network module...
Server reachable: False
Client response: Error: Cannot connect to server at localhost:8080This is expected behavior because the server is not running. To fix this, start the server first,
$ python3 network_handler.py serverThen run the client again to send data.
An individual course project by Shlok Mehendale