小编Gor*_*oon的帖子

Python认为json是局部变量

该函数应该操作存储为文件的字典中的值。我正进入(状态

“赋值前引用的局部变量‘json’”

第四行,“dictio = json.loads()。”

我已经导入了 json,事实上下面的函数运行得很好,执行几乎相同的任务。与后面的函数不同,即使我没有故意要求多线程,这个函数也会抛出一个空队列错误。

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()
Run Code Online (Sandbox Code Playgroud)

def record_score(score): # 打开、读取、写入和关闭分数文件,20QScores.txt (filename) 全局总分数 f = open(filename, "r") # 记录并报告个人的回答 sf = json.loads( Scoref.read()) # Json 有助于字符串和整数写入和读取文件。key = str(score) if key in sf: sf[key] += 1 else: …

variables json scope local

2
推荐指数
1
解决办法
6259
查看次数

标签 统计

json ×1

local ×1

scope ×1

variables ×1