Vibhu Sharma
Vibhu Sharma

Reputation: 7

IndentationError: expected an indented block (JSON_Project.py, line 22)

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)
        

        }

"IndentationError: expected an indented block (JSON_Project.py, line 22)". Can anyone help me remove this error and run my code in Python? I will run this code then in a terminal or command Prompt

Upvotes: -1

Views: 44

Answers (1)

willcrack
willcrack

Reputation: 1852

In python, code blocks are made through identation(instead of {}). So you just needed to add indentation on the blocks that are inside each for loop. Also, remove {}

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)

For instance, this part is inside the function and both for loops:

            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)

And this part is just inside the function:

    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)

Upvotes: 1

Related Questions