I know this is a common question but I could not find the solution for my case. I have gotten a problem while a for-loop in Python. When I run a program with this piece
for j in range(len(line1)- 3):
print 'j =', j
spl1 = spline(line1[j], line1[j + 1], line1[j + 2], line1[j + 3], t, Nu)
print 'spl1 ='
matrix.show(spl1)
i get an output:
Traceback (most recent call last):
File "D:\work\curvature\test\twisted\cardinal_spline.py", line 272, in <module> main()
File "D:\work\curvature\test\twisted\cardinal_spline.py", line 111, in main
matrix.show(spl1)
UnboundLocalError: local variable 'spl1' referenced before assignment
Moreover, it does not print j-variable. I cannot see any mistake there. The “spl1” is assigned in the for-loop but it looks like the interpreter just skips it.
please point on the mistake.
Your for-loop doesn’t get executed at all due to
len(line1) <= 3in some cases, sospl1isn’t assigned.