added argv to add any txt file
This commit is contained in:
8
main.py
8
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 <path_to_book>")
|
||||
sys.exit(1)
|
||||
|
||||
read_file = get_book_text(sys.argv[1])
|
||||
counted = count_words(read_file)
|
||||
counted_chars = count_characters(read_file)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user