Last active
August 29, 2015 14:12
-
-
Save cchurch/a4c5778f5f8ced0b01d7 to your computer and use it in GitHub Desktop.
Response to TriPython mailing list question: http://starship.python.net/pipermail/triangle-zpug/2014-December/001963.html
This file contains 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
{ | |
"log": { | |
"id": "http://192.168.43.81:8080/api/collections/nodes/node1/log", | |
"name": "log" | |
}, | |
"tags": [], | |
"facts": { | |
"hardwareisa": "x86_64", | |
"macaddress": "08:00:27:e7:06:4d", | |
"architecture": "x86_64", | |
"hardwaremodel": "x86_64", | |
"processor0": "Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz", | |
"processorcount": "1", | |
"interfaces": "enp0s17,lo", | |
"ipaddress_enp0s17": "192.168.1.63" | |
} | |
} |
This file contains 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 | |
# Option 1: Read JSON directly from file object: | |
data = json.load(open('data.json')) | |
# Option 2: Read file into string, then parse as JSON: | |
s = open('data.json').read() | |
data = json.loads(s) | |
# Read the MAC address from the data, or set to None if it can't be found. | |
try: | |
macaddress = data['facts']['macaddress'] | |
except KeyError: | |
macaddress = None | |
print(macaddress) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment