name 'times' is used prior to global declaration - But IT IS declared!
From the Python documentation:
Names listed in a global statement must not be used in the same code block textually preceding that global statement.
https://docs.python.org/reference/simple_stmts.html#global
So moving global times
to the top of the function should fix it.
But, you should try not to use global
in this situation. Consider using a class.
From the Python Docs
Names listed in a global statement must not be used in the same code block textually preceding that global statement.
The global declaration is when you declare that times
is global
def timeit():
global times # <- global declaration
# ...
If a variable is declared global
, it can't be used before the declaration.
In this case, I don't think you need the declaration at all, because you're not assigning to times
, just modifying it.