mardi 23 juin 2015

python if statement inside for syntax error

I wrote some code but I can't get why the pyscripter is telling a syntax error in the if statement:

#search for 9 elements
file_writer = open('C:\\PythonProject2\\commands_NUM.txt','w')
for item in data_indices:
    flag= search_object(item,data,obj_value_min,obj_value_max)
        if flag = True:###ERROR
            file_writer.write('frame0: ' + str(item[0]+1)+' ' + str(item[1]+1) + '\n') ##Here is the syntax error

file_writer.close()

def search_object(pixel,frame,min_val,max_val):
    (obj_y,obj_x) = pixel
    y_center = pixel[0]+1
    x_center = pixel[1]+1
    if(obj_y<=597 and obj_x<=797 ):
        for y in range(0,3):
            for x in range(0,3):
                if((frame[obj_y+y][obj_x+x])<=min_val or(frame[obj_y+y]    [obj_x+x])>=max_val ):
                    return False

return True

Aucun commentaire:

Enregistrer un commentaire