forked from realpython/materials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcount.py
More file actions
32 lines (22 loc) · 819 Bytes
/
Copy pathcount.py
File metadata and controls
32 lines (22 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import sys
import time
import colorama
from colorama import Cursor
colorama.init()
def print_at(row, text):
print(Cursor.POS(1, 1 + row) + str(text))
time.sleep(0.03)
def count_lines_in_file(file_num, file_name):
counter_text = f"{file_name[:20]:<20} "
with open(file_name, mode="rt", encoding="utf-8") as file:
for line_num, _ in enumerate(file, start=1):
counter_text += "□"
print_at(file_num, counter_text)
print_at(file_num, f"{counter_text} ({line_num})")
def count_all_files(file_names):
for file_num, file_name in enumerate(file_names, start=1):
count_lines_in_file(file_num, file_name)
if __name__ == "__main__":
print(colorama.ansi.clear_screen())
count_all_files(sys.argv[1:])
print(Cursor.POS(1, 1 + len(sys.argv)))