Python 如何使用烧瓶清除dict[已解决]

Python 如何使用烧瓶清除dict[已解决],python,flask,Python,Flask,每次调用路由时,我都试图从字典中清除数据 app = Flask(__name__) CORS(app) @app.route('/compile', methods=["POST"]) def compile(): content = request.get_json() quadDict = {} size = [] # Here we will pass to the vm # and return the result of the vm to the f

每次调用路由时,我都试图从字典中清除数据

app = Flask(__name__)
CORS(app)
@app.route('/compile', methods=["POST"])
def compile():
 content = request.get_json()
 quadDict = {}
 size = []
 # Here we will pass to the vm 
 # and return the result of the vm to the front
 result = parser.parse(content['code'])
 print('////', len(quadruples))
 size = [i for i in range(0, len(quadruples))]
 lista = []
 for element in quadruples:
    lista.append(element.generateLista())
 quadDict = dict(zip(size, lista))
 print(content['codigo'])
 print(quadDict)
 return quadDict
if __name__ == '__main__':
 app.run(debug=True)
代码正在传递作为字典生成的四元组,并将四元组返回到前面,但它正在字典上添加,而不是在每次调用时重新启动

-尝试创建函数以重新启动它,但未成功。。。 四位数是没有索引号的列表

quadDict第一次运行示例:

0 -> GOTO,main,,17
1 -> =,10000,,1002
2 -> ==,1002,10001,7000
3 -> GOTOF,7000,,9
4 -> +,10002,10003,7001
5 -> =,7001,,1000
6 -> +,1002,1,7002
7 -> =,7002,,1002
8 -> GOTO,,,2
9 -> *,10005,10006,7003
10 -> /,7003,10007,7004
11 -> +,10004,7004,7005
12 -> =,7005,,1000
13 -> *,10008,10009,7006
14 -> =,7006,,1001
15 -> ENDPROG,,,
quadDict第二次运行示例:

0 -> GOTO,main,,17
1 -> =,10000,,1002
2 -> ==,1002,10001,7000
3 -> GOTOF,7000,,9
4 -> +,10002,10003,7001
5 -> =,7001,,1000
6 -> +,1002,1,7002
7 -> =,7002,,1002
8 -> GOTO,,,2
9 -> *,10005,10006,7003
10 -> /,7003,10007,7004
11 -> +,10004,7004,7005
12 -> =,7005,,1000
13 -> *,10008,10009,7006
14 -> =,7006,,1001
15 -> ENDPROG,,,
16 -> GOTO,main,,
17 -> =,10010,,1007
18 -> ==,1007,10011,7000
19 -> GOTOF,7000,,25
20 -> +,10012,10013,7001
21 -> =,7001,,1005
22 -> +,1007,1,7002
23 -> =,7002,,1007
24 -> GOTO,,,18
25 -> *,10015,10016,7003
26 -> /,7003,10017,7004
27 -> +,10014,7004,7005
28 -> =,7005,,1005
29 -> *,10018,10019,7006
30 -> =,7006,,1006
31 -> ENDPROG,,,
正如我们所观察到的,它将先前生成的四倍体附加到JSON中的新四倍体

谢谢大家!

对不起,没有在原帖上解释


[如果再次调用代码端点,则需要重新启动变量四倍]

四倍从何而来?它不显示在代码中。shorter:size=listrange0,LenFourples,但您甚至可以assing size=range0,LenFourples和zipsize。。。如果仍然有效,您甚至可以直接创建没有大小的quadDict和lista-对于数字,枚举四元组中的元素:quadDict[number]=element。generateLista@noslenkwah当parser.parsecontent[code]运行时会生成四个,它是一个列表,问题是,当我在运行文件的同时再次运行代码时,它会将结果附加到以前生成的quadDict中。@furas它工作了,但没有按照我的意图执行,