I got the error "UnboundLocalError: local variable 'start_time' referenced before assignment" when running the code below. How can I solve this issue?
I use Spyder (Python 2.7), Windows 7 Ultimate. My full code line here
I got the error "UnboundLocalError: local variable 'start_time' referenced before assignment" when running the code below. How can I solve this issue?
I use Spyder (Python 2.7), Windows 7 Ultimate. My full code line here
Since there is no code:
exception UnboundLocalError
Raised when a reference is made to a local variable in a function or method, but no value has been bound to that variable. This is a subclass of NameError. [reference]
So in this example:
counter = 0
def count():
counter += 1
return counter
count()
You would get an UnboundLocalError because even though counter is assigned up top, within the scope of the function (locally) it is not. It is referenced before it has been assigned.
Likely in your code, start_time
is being evaluated or added to or something else before it has actually been assigned, i.e. before it holds any value.