Skip to content

Instantly share code, notes, and snippets.

@tmcolby
Created May 7, 2019 16:54
Show Gist options
  • Save tmcolby/27fe2ad68bd005e75c5356f02ba525fb to your computer and use it in GitHub Desktop.
Save tmcolby/27fe2ad68bd005e75c5356f02ba525fb to your computer and use it in GitHub Desktop.
using json configuration file for python
{
"rs485": {
"method" : "rtu",
"port" : "/dev/ttyUSB2",
"baudrate" : 9600,
"stopbits" : 1,
"parity" : "N",
"timeout" : 5
},
"modbus": {
"unit" : 1
}
}
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