First software job and l inherited a codebase with heavy JSON usage. I'm trying to use Python to load a text file from accessing a JSON element. My relative path understanding is limited but l'm able to load python modules in the same sub directory (not using JSON though). This data file is in the same folder.
I parse and store data within the JSON element here:
with open(cfg) as fp:
edict = json.load(fp)
if edict["dtype"] == "custom" :
data = edict["dtype"]["custom"]["datapath"]
Relevant section of JSON file:
{
"dtype" : {
"custom" : {
"datapath" : "DataPipeLine/example_data.txt",
"type" : "T",
"X" : "encoder",
"Y" : "encoder"
}
}
}
I get an error from passing the data variable into a function later in the program:
UnboundLocalError: local variable referenced before assignment error is raised when you try to assign a value to a local variable before it has been declared.