Skip to content

Instantly share code, notes, and snippets.

@tmcolby
Last active April 5, 2019 15:15
Show Gist options
  • Save tmcolby/d0adef25795ce2cbdb76cb9a0aca7ffb to your computer and use it in GitHub Desktop.
Save tmcolby/d0adef25795ce2cbdb76cb9a0aca7ffb to your computer and use it in GitHub Desktop.
using yaml configuration file for python
database:
username: admin
password: foobar # TODO get prod passwords out of config
socket: /var/tmp/database.sock
options: {use_utf8: true}
memcached:
host: 10.0.0.99
workers:
- host: 10.0.0.101
port: 2301
- host: 10.0.0.102
port: 2302
import yaml
import pprint
config = yaml.safe_load(open('config.yml'))
pprint.pprint(config)
{'database': {'options': {'use_utf8': True},
'password': 'foobar',
'socket': '/var/tmp/database.sock',
'username': 'admin'},
'memcached': {'host': '10.0.0.99'},
'workers': [{'host': '10.0.0.101', 'port': 2301},
{'host': '10.0.0.102', 'port': 2302}]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment