forked from ls1248659692/python_guide
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyml_analysis.py
More file actions
71 lines (53 loc) · 1.31 KB
/
yml_analysis.py
File metadata and controls
71 lines (53 loc) · 1.31 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
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/python
# coding=utf8
import json
import yaml
__author__ = 'Jam'
__date__ = '2019/4/22 14:12'
def check_yml():
yml_str = """
root:
user:
name: Jam
sex: man
company:
- floor: 10
- number: 9527
- depends_on:
- capvision
- baidu
site:
- shanghai
- wuhan
- chengdu
- hangzhou
"""
yml_data = yaml.load(yml_str)
return yml_data
class YamlAnalysis(object):
def __init__(self):
self.data = None
def get_config(self):
with open('./data/config.yml', 'r') as f:
yml_data = f.read()
self.data = yaml.load(yml_data)
return self.data
class InitExample:
name = 'Gxs'
def __init__(self, name, height, weight):
self.name = name
self.height = height
self.weight = weight
def main():
yml_str = check_yml()
yml_config = YamlAnalysis().get_config()
print type(yml_str), type(yml_config)
print json.dumps(yml_str, indent=4, sort_keys=True)
print json.dumps(yml_config, indent=4, sort_keys=True)
init_example = InitExample('Jam', 180, 18)
print InitExample.name
print init_example.name
print init_example.height
print init_example.weight
if __name__ == '__main__':
main()