"IndentationError: expected an indented block (JSON_Project.py, line 22)" .任何人都可以帮助我删除此错误并在 Python


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)

}

"缩进错误:应为缩进块(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)

例如,这一部分在函数内部,并且两者都用于循环:

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)

相关内容

最新更新