-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
48 lines (38 loc) · 1.12 KB
/
Copy pathutils.py
File metadata and controls
48 lines (38 loc) · 1.12 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
import json
import os
def save_tasks(tasks):
with open("tasks.json","w") as f:
json.dump(tasks,f,indent=4)
def load_tasks():
try:
with open("tasks.json","r") as f:
return json.load(f)
except FileNotFoundError:
return []
except json.JSONDecodeError:
return[]
def clear():
os.system("cls" if os.name=="nt" else "clear")
def get_int(msg):
while True:
try:
x=input(msg).strip()
if x.lower()=="cancel":
return None
else:
x=int(x)
return x
except ValueError:
print("Please enter a valid numeric value")
def get_input(msg,allow_empty=False,max_len=None):
while True:
value= input(msg).strip().lower()
if value == "cancel":
return None
if not value and not allow_empty:
print("Input can't be empty")
continue
if max_len and len(value)> max_len:
print(f"Keep it under {max_len} characters")
continue
return value