I am currently initializing variables within if else statements by .extend(). At the end of my script I am writing the variables to an excel file using xlwt. However the compiler throws the following error:
Traceback (most recent call last):
File "C:\Python27\cascade.py", line 171, in <module>
NameError: name 'correct_screw_match' is not defined>
Currently I am also using extend as an error is thrown when using append.
for i in range (no_of_screw)
for iterator in range (0, read_limit, 2):
if (excel_screw_centroid[iterator]-25) <= screw_centroid[i,1] <= (excel_screw_centroid[iterator]+25):
if (excel_screw_centroid[iterator+1]-25) <= screw_centroid[i,0] <= (excel_screw_centroid[iterator+1]+25):
correct_screw_match.extend(i)
detected_a_screw = 1
else:
incorrect_screw_match.extend(i)
detected_a_screw = 0
I assume that the reason is, that the variables are declared within within an if else statement. This is why I initialized the variable as empty in the beginning of the script in the following way:
correct_screw_match = None
This however gives the following problem:
Traceback (most recent call last):
File "C:\Python27\cascade.py", line 106, in <module>
AttributeError: 'NoneType' object has no attribute 'extend'
The below to links explains in a simple manner, how to declare an empty variable, and the other how to append to it within if statements. I am however unaware of why this is not possible to me in the current way.