A simple class for converting a *.cfg file to a Python Dictionary
Project description
-- ConfigToDictionary
Convert a python config file of to a python dictionary
-- Example
Return the information in `info.cfg` as a `JSON` response from a `Flask` server:
info.cfg
----------
[info]
name = risk
version = 1
description = A simple game of chance. Risk 1000 Satoshis, win 2000, or lose them all.
project = https://github.com/joelklabo/risk
[risk]
price = 1000
description = 49/100 chance you will double your satoshis
```
server.py
----------
from flask import Flask
from flask.ext.responses import json_response
from cfgtodict import ConfigToDictionary
app = Flask(__name__)
@app.route('/info')
def info():
about = ConfigToDictionary('info.cfg').dict()
return json_response(about)
```
JSON response
----------
{
"info": {
"description": "A simple game of chance. Risk 1000 Satoshis, win 2000, or lose them all.",
"name": "risk",
"project": "https://github.com/joelklabo/risk",
"version": "1"
},
"risk": {
"description": "49/100 chance you will double your satoshis",
"price": "1000"
}
}
```
Convert a python config file of to a python dictionary
-- Example
Return the information in `info.cfg` as a `JSON` response from a `Flask` server:
info.cfg
----------
[info]
name = risk
version = 1
description = A simple game of chance. Risk 1000 Satoshis, win 2000, or lose them all.
project = https://github.com/joelklabo/risk
[risk]
price = 1000
description = 49/100 chance you will double your satoshis
```
server.py
----------
from flask import Flask
from flask.ext.responses import json_response
from cfgtodict import ConfigToDictionary
app = Flask(__name__)
@app.route('/info')
def info():
about = ConfigToDictionary('info.cfg').dict()
return json_response(about)
```
JSON response
----------
{
"info": {
"description": "A simple game of chance. Risk 1000 Satoshis, win 2000, or lose them all.",
"name": "risk",
"project": "https://github.com/joelklabo/risk",
"version": "1"
},
"risk": {
"description": "49/100 chance you will double your satoshis",
"price": "1000"
}
}
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
cfgtodict-0.1.3.tar.gz
(1.2 kB
view details)
File details
Details for the file cfgtodict-0.1.3.tar.gz
.
File metadata
- Download URL: cfgtodict-0.1.3.tar.gz
- Upload date:
- Size: 1.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67b4cf0a7b7124e0b279d8f5801218c2382937a11e65e530ef6d0b4c682f9040 |
|
MD5 | a53e53ae6c7aa85b1b59adcc714dfc60 |
|
BLAKE2b-256 | 79461e0a1a64c9e70aaf9f5d7275f8456b884ec4b7f6c71868d1de5eab255088 |