added argv to add any txt file

This commit is contained in:
2025-06-27 15:55:25 +02:00
parent 16c1c1f5b1
commit 28c3c7d68b

View File

@@ -2,12 +2,18 @@ from stats import count_words
from stats import count_characters from stats import count_characters
from stats import sort_by_count from stats import sort_by_count
import sys
def get_book_text(filepath): def get_book_text(filepath):
with open(filepath) as f: with open(filepath) as f:
return f.read() return f.read()
def main(): def main():
read_file = get_book_text("books/frankenstein.txt") if len(sys.argv) < 2:
print("Usage: python3 main.py <path_to_book>")
sys.exit(1)
read_file = get_book_text(sys.argv[1])
counted = count_words(read_file) counted = count_words(read_file)
counted_chars = count_characters(read_file) counted_chars = count_characters(read_file)