-
Notifications
You must be signed in to change notification settings - Fork 213
/
Copy pathmain.py
62 lines (48 loc) · 1.27 KB
/
main.py
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
59
60
61
62
import os
import pathlib
def analyze_data(file: str):
if not os.path.exists(file):
# if not os.path.isfile(file):
# if not os.path.isdir(file):
print(f"Does not exist: {file}")
return
with open(file) as fp:
...
def analyze_data(file: str):
try:
with open(file) as fp:
data = fp.read()
except FileNotFoundError:
print(f"Does not exist: {file}")
def analyze_data(file: str):
try:
data = pathlib.Path(file).read_text()
except FileNotFoundError:
print(f"Does not exist: {file}")
except OSError:
print(f"Failed to open: {file}")
else:
...
def analyze_data(path: pathlib.Path):
try:
data = path.read_text()
except FileNotFoundError:
print(f"Does not exist: {path}")
except OSError:
print(f"Failed to open: {path}")
else:
...
def initialize_app():
config_dir = "."
if is_user_config_dir_present(config_dir):
... # load config files
else:
... # load defaults
def your_options():
# file = "/path/to/some/file.txt"
# path = pathlib.Path(file)
path = pathlib.Path("path", "to", "some", "file.txt")
if path.is_dir():
print("Found")
else:
print("Not found")