&引用;缩进错误:应为缩进块(JSON_Project.py,第22行);。有人能帮我删除这个错误并用Python运行我的代码吗?

&引用;缩进错误:应为缩进块(JSON_Project.py,第22行);。有人能帮我删除这个错误并用Python运行我的代码吗?,python,arrays,for-loop,math,nested-loops,Python,Arrays,For Loop,Math,Nested Loops,“缩进错误:应为缩进块(JSON_Project.py,第22行)”。有人能帮我删除这个错误并用Python运行我的代码吗?我将在python中的终端或命令提示符下运行此代码,代码块是通过标识(而不是{})生成的。 所以您只需要在每个for循环内的块上添加缩进。另外,删除{} def json_maker(angledeg,collangledeg): for angledeg in angledeg_list: { for collangledeg in collang

“缩进错误:应为缩进块(JSON_Project.py,第22行)”。有人能帮我删除这个错误并用Python运行我的代码吗?我将在python中的终端或命令提示符下运行此代码,代码块是通过标识(而不是{})生成的。 所以您只需要在每个for循环内的块上添加缩进。另外,删除{}

def json_maker(angledeg,collangledeg):
for angledeg in angledeg_list:
    {
        for collangledeg in collangledeg_list:

point1 = "0,0,0"
point2 = str(L) + ",0,0"
point3 = str(L-W*math.cos(angle)) + "," + str(W*math.sin(angle)) + ",0" 
point4 = str(-W*math.cos(angle)) + "," + str(W*math.sin(angle)) + ",0"
point5 = "0,0," + str(-d)
point6 = str(L) + ",0," + str(-d)
point7 = str(L-W*math.cos(angle)) + "," + str(W*math.sin(angle)) + "," + str(-d)
point8 = str(-W*math.cos(angle)) + "," + str(W*math.sin(angle)) + "," + str(-d)

surface1 = [point2, point3, point7, point6]
surface2 = [point1, point5, point8, point4] 
surface3 = [point1, point2, point6, point5]
surface4 = [point1, point4, point3, point2] 
surface5 = [point5, point6, point7, point8]
surface6 = [point4, point8, point7, point3]

dict1 = {'emits': 'false', 'diffuse': 'true', 'e': emissivity_roof, "pnts": surface3} 
dict2 = {'emits': 'false', 'diffuse': 'false', 'e': emissivity_back_panel, "pnts": surface2}
dict3 = {'emits': 'false', 'diffuse': 'false', 'e': emissivity_back_panel, "pnts": surface1} 
dict4 = {'emits': 'false', 'e': 0.0, "pnts": surface4}
dict5 = {'emits': 'false', 'e': 0.0, "pnts": surface5}
dict6 = {'emits': 'true', 'collimate': str(-math.sin(collangle)) + ',' + str(-math.cos(collangle)) +',0', 'e': 1.0, "pnts": surface6}

surfaces.extend([dict1, dict2, dict3, dict4, dict5, dict6])

listentry = {'name': str(angledeg) + ' ' + str(collangledeg) , 'faces': surfaces}

outputdata.append(listentry)

with open('Inf_coll_spec_' + str(int(emissivity_roof*1000)) + '.json', 'w') as outfile:
    json.dump({ "traces" : outputdata }, outfile)
    
    result.list=[ angledeg, collangledeg, dict3, dict2, dict1, dict6]
        results.append(result.list)
        

        }
例如,此部分位于函数内部,两个部分都用于循环:

def json_maker(angledeg,collangledeg):
    for angledeg in angledeg_list:
        
        for collangledeg in collangledeg_list:

            point1 = "0,0,0"
            point2 = str(L) + ",0,0"
            point3 = str(L-W*math.cos(angle)) + "," + str(W*math.sin(angle)) + ",0" 
            point4 = str(-W*math.cos(angle)) + "," + str(W*math.sin(angle)) + ",0"
            point5 = "0,0," + str(-d)
            point6 = str(L) + ",0," + str(-d)
            point7 = str(L-W*math.cos(angle)) + "," + str(W*math.sin(angle)) + "," + str(-d)
            point8 = str(-W*math.cos(angle)) + "," + str(W*math.sin(angle)) + "," + str(-d)

            surface1 = [point2, point3, point7, point6]
            surface2 = [point1, point5, point8, point4] 
            surface3 = [point1, point2, point6, point5]
            surface4 = [point1, point4, point3, point2] 
            surface5 = [point5, point6, point7, point8]
            surface6 = [point4, point8, point7, point3]

            dict1 = {'emits': 'false', 'diffuse': 'true', 'e': emissivity_roof, "pnts": surface3} 
            dict2 = {'emits': 'false', 'diffuse': 'false', 'e': emissivity_back_panel, "pnts": surface2}
            dict3 = {'emits': 'false', 'diffuse': 'false', 'e': emissivity_back_panel, "pnts": surface1} 
            dict4 = {'emits': 'false', 'e': 0.0, "pnts": surface4}
            dict5 = {'emits': 'false', 'e': 0.0, "pnts": surface5}
            dict6 = {'emits': 'true', 'collimate': str(-math.sin(collangle)) + ',' + str(-math.cos(collangle)) +',0', 'e': 1.0, "pnts": surface6}

            surfaces.extend([dict1, dict2, dict3, dict4, dict5, dict6])

            listentry = {'name': str(angledeg) + ' ' + str(collangledeg) , 'faces': surfaces}

            outputdata.append(listentry)

    with open('Inf_coll_spec_' + str(int(emissivity_roof*1000)) + '.json', 'w') as outfile:
        json.dump({ "traces" : outputdata }, outfile)

        result.list=[ angledeg, collangledeg, dict3, dict2, dict1, dict6]
        results.append(result.list)
这部分就在函数内部:

            point1 = "0,0,0"
            point2 = str(L) + ",0,0"
            point3 = str(L-W*math.cos(angle)) + "," + str(W*math.sin(angle)) + ",0" 
            point4 = str(-W*math.cos(angle)) + "," + str(W*math.sin(angle)) + ",0"
            point5 = "0,0," + str(-d)
            point6 = str(L) + ",0," + str(-d)
            point7 = str(L-W*math.cos(angle)) + "," + str(W*math.sin(angle)) + "," + str(-d)
            point8 = str(-W*math.cos(angle)) + "," + str(W*math.sin(angle)) + "," + str(-d)

            surface1 = [point2, point3, point7, point6]
            surface2 = [point1, point5, point8, point4] 
            surface3 = [point1, point2, point6, point5]
            surface4 = [point1, point4, point3, point2] 
            surface5 = [point5, point6, point7, point8]
            surface6 = [point4, point8, point7, point3]

            dict1 = {'emits': 'false', 'diffuse': 'true', 'e': emissivity_roof, "pnts": surface3} 
            dict2 = {'emits': 'false', 'diffuse': 'false', 'e': emissivity_back_panel, "pnts": surface2}
            dict3 = {'emits': 'false', 'diffuse': 'false', 'e': emissivity_back_panel, "pnts": surface1} 
            dict4 = {'emits': 'false', 'e': 0.0, "pnts": surface4}
            dict5 = {'emits': 'false', 'e': 0.0, "pnts": surface5}
            dict6 = {'emits': 'true', 'collimate': str(-math.sin(collangle)) + ',' + str(-math.cos(collangle)) +',0', 'e': 1.0, "pnts": surface6}

            surfaces.extend([dict1, dict2, dict3, dict4, dict5, dict6])

            listentry = {'name': str(angledeg) + ' ' + str(collangledeg) , 'faces': surfaces}

            outputdata.append(listentry)

在python中,通过使用缩进而不是括号来构造代码。阅读此参考检查缩进也删除
{}
这是否回答了您的问题?
    with open('Inf_coll_spec_' + str(int(emissivity_roof*1000)) + '.json', 'w') as outfile:
        json.dump({ "traces" : outputdata }, outfile)

        result.list=[ angledeg, collangledeg, dict3, dict2, dict1, dict6]
        results.append(result.list)