From 28c3c7d68b4d637a6d921e93ab6c5afede242859 Mon Sep 17 00:00:00 2001 From: htom Date: Fri, 27 Jun 2025 15:55:25 +0200 Subject: [PATCH] added argv to add any txt file --- main.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index fc3f328..c6ef110 100644 --- a/main.py +++ b/main.py @@ -2,12 +2,18 @@ from stats import count_words from stats import count_characters from stats import sort_by_count +import sys + def get_book_text(filepath): with open(filepath) as f: return f.read() def main(): - read_file = get_book_text("books/frankenstein.txt") + if len(sys.argv) < 2: + print("Usage: python3 main.py ") + sys.exit(1) + + read_file = get_book_text(sys.argv[1]) counted = count_words(read_file) counted_chars = count_characters(read_file)