import json
# import Adafruit_DHT
CONFIG_FILE = "config.json"
class Config():
def __init__(self):
with open(CONFIG_FILE) as config_file:
self.config_data = json.load(config_file)
locals().update(self.config_data)
print(Sensor_DHT11_PIN)
def get(self, key):
return self.config_data[key]
def Main ():
var = Config()
print(var.get("Sensor_DHT11_PIN"))
if __name__ == '__main__':
Main()
#ERROR MESSAGE:
#$ python loadconfig.py
#4
#Traceback (most recent call last):
# File "loadconfig.py", line 23, in <module>
# Main()
#File "loadconfig.py", line 20, in Main
# print(Sensor_DHT11_PIN)
#NameError: name 'Sensor_DHT11_PIN' is not defined
I want to be able to call a particular key from the dictionary and obtain that value, using the dictionary key as a variable, but when I run the function. I obtain the value trough the "get" function of the Config class but no as a varible drawn out of the dicitonary:
How can I make this possible?