Skip to content

Instantly share code, notes, and snippets.

@allenyang79
Created August 15, 2018 05:56
Show Gist options
  • Save allenyang79/8e9b3e88a7f3cd87c8a39e3bf7dbd2d6 to your computer and use it in GitHub Desktop.
Save allenyang79/8e9b3e88a7f3cd87c8a39e3bf7dbd2d6 to your computer and use it in GitHub Desktop.
use yaml as config, 似乎不是很理想
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