Created
May 7, 2019 16:54
-
-
Save tmcolby/27fe2ad68bd005e75c5356f02ba525fb to your computer and use it in GitHub Desktop.
using json configuration file for python
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
{ | |
"rs485": { | |
"method" : "rtu", | |
"port" : "/dev/ttyUSB2", | |
"baudrate" : 9600, | |
"stopbits" : 1, | |
"parity" : "N", | |
"timeout" : 5 | |
}, | |
"modbus": { | |
"unit" : 1 | |
} | |
} |
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 json | |
with open('config.json') as fp: | |
config = json.load(fp) | |
port = config['rs485']['port'] | |
baudrate = config['rs485']['baudrate'] | |
. | |
. | |
. | |
etc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment