-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
58 lines (48 loc) · 1.55 KB
/
utils.py
File metadata and controls
58 lines (48 loc) · 1.55 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from prettytable import PrettyTable
def print_table(rows, headers):
table = PrettyTable()
table.field_names = headers
for row in rows:
table.add_row(row)
print(table)
def print_separator(title=""):
width = 64
if title:
print(f"\n{'=' * width}")
print(title.center(width))
print(f"{'=' * width}")
else:
print("=" * width)
def get_int_input(prompt, min_val=None, max_val=None):
while True:
try:
value = int(input(prompt))
if min_val is not None and value < min_val:
print(f"Value must be at least {min_val}.")
continue
if max_val is not None and value > max_val:
print(f"Value must be at most {max_val}.")
continue
return value
except ValueError:
print("Please enter a valid integer.")
def get_float_input(prompt, min_val=0.0):
while True:
try:
value = float(input(prompt))
if value < min_val:
print(f"Value must be at least {min_val}.")
continue
return value
except ValueError:
print("Please enter a valid number.")
def get_str_input(prompt, max_length=None):
while True:
value = input(prompt).strip()
if not value:
print("Input cannot be empty.")
continue
if max_length and len(value) > max_length:
print(f"Input must be at most {max_length} characters.")
continue
return value