This function is supposed to manipulate values in a dictionary stored as a file. I am getting
"local variable 'json' referenced before assignment"
on the fourth line, "dictio = json.loads()."
I have imported json, in fact the function below this runs perfectly well performing almost the same task. Unlike the later function, this one is also throwing an empty queue error, even though I have not intentionally asked for multithreading.
def updateTally(lefty): #Tally records responses to each question
global num, total, thisQ
rf = open("20QTally.json", "r")
dictio = json.loads(rf.read())
rf.close()
dictio[str(0)] += 1
total = dictio[str(0)]
if lefty == 1:
dictio[str(num)] +=1
thisQ = dictio[str(num)]
json = json.dumps(dictio)
wf = open("20QTally.json", "w")
wf.write(json)
wf.close()
def record_score(score): # Opens, reads, writes, and closes the score file, 20QScores.txt (filename) global total scoref = open(filename, "r") # Records and reports individuals' responses sf = json.loads(scoref.read()) # Json helps with string and integer writing and reading to files. key = str(score) if key in sf: sf[key] += 1 else: sf[key] = 1 #etc.