At the top of my script I have count = 0. A function that does print(count) works. A callback that does count += 1 fails with UnboundLocalError, saying the local variable is referenced before assignment. Strangely, even a print(count) on the line before the increment fails once the increment is in the function.
Why does adding an assignment later in the function break an earlier read, and what is the right way to keep a counter that a callback updates?




