-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakejson03.py
39 lines (28 loc) · 1 KB
/
makejson03.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/python3
"""opening a static file containing JSON data | Alta3 Research"""
# JSON is part of the Python Standard Library
import json
def main():
"""runtime code"""
## open the file
with open("datacenter.json", "r") as datacenter:
datacenterstring = datacenter.read()
## display our decoded string
print(datacenterstring)
print(type(datacenterstring))
print("\nThe code above is string data. Python cannot easily work with this data.")
input("Press Enter to continue\n")
## Create the JSON string
datacenterdecoded = json.loads(datacenterstring)
## This is now a dictionary
print(type(datacenterdecoded))
## display the servers in the datacenter
print(datacenterdecoded)
## display the servers in row3
print(datacenterdecoded["row3"])
## display the 2nd server in row2
print(datacenterdecoded["row2"][1])
## write code to
## display the last server in row3
if __name__ == "__main__":
main()