Created
August 15, 2018 05:56
-
-
Save allenyang79/8e9b3e88a7f3cd87c8a39e3bf7dbd2d6 to your computer and use it in GitHub Desktop.
use yaml as config, 似乎不是很理想
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import yaml | |
import configparser | |
# print(dir(yaml)) | |
data = yaml.load(""" | |
a: | |
a1: a1 | |
a2: a2 | |
a3: "%(a1)s-%(a2)s" | |
b: | |
b1: b1 | |
b2: b2 | |
b3: | |
- 1 | |
- 2 | |
- 3 | |
- oops | |
""") | |
print(data) | |
parser = configparser.ConfigParser() | |
parser.read_dict(data) | |
for section in parser.sections(): | |
print(section) | |
for key, value in parser.items(section): | |
print(key, value) | |
#print (parser.items(section,)) | |
print(repr(parser.get('b', 'b3'))) | |
print(repr(parser.get('b', 'b3'))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment