yaml
import yaml
with open('config.yml', 'w') as yaml_file:
yaml.dump({
'web_server': {
'host': '127.0.0.1',
'port': 80
},
'db_server': {
'host': '127.0.0.1',
'port': 3306
}
}, yaml_file)
with open('config.yml', 'r') as yaml_file:
data = yaml.load(yaml_file)
print(data, type(data))
print(data['web_server']['host'])
print(data['web_server']['port'])
print(data['db_server']['host'])
print(data['db_server']['port'])
出力結果:
{'db_server': {'host': '127.0.0.1', 'port': 3306}, 'web_server': {'host': '127.0.0.1', 'port': 80}} <class 'dict'>
127.0.0.1
80
127.0.0.1
3306
Author And Source
この問題について(yaml), 我々は、より多くの情報をここで見つけました https://qiita.com/hikurochan/items/f4f58b0347fd1e3d21c7著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .