Skip to content

Commit e029363

Browse files
committed
Annottation for get value form yaml
1 parent a24738f commit e029363

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

main.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
1+
import pdb
2+
13
import yaml
24

3-
def readYaml(path) -> {}:
4-
config = {}
5-
with open(path) as file:
6-
try:
7-
config = yaml.safe_load(file)
8-
except yaml.YAMLError as exc:
9-
print(exc)
10-
return config
5+
6+
class Yaml():
7+
8+
def __init__(self, path):
9+
super(Yaml, self).__init__()
10+
self.config = self.readYaml(path)
11+
12+
def value(self, value: str):
13+
def fun(f):
14+
values = value.split(".")
15+
r_value = None
16+
for v in values:
17+
r_value = self.config[v] if r_value is None else r_value[v]
18+
return r_value
19+
20+
return fun
21+
22+
def readYaml(self, path) -> {}:
23+
config = {}
24+
with open(path) as file:
25+
try:
26+
config = yaml.safe_load(file)
27+
except yaml.YAMLError as exc:
28+
print(exc)
29+
return config

0 commit comments

Comments
 (0)