Small question about globals. I have the following code:
counter = 0
class A():
global counter
def connect():
counter += 1
print("Opening connection",counter)
# DO STUFF
def disconnect():
counter -= 1
print("Closing connection",counter)
# DO STUFF
Each time I connect or disconnect, I want to know the number of opened connections counter (not just for one instance, rather for all of the instances, so it should be static). But when running the code I get:
local variable 'counter' referenced before assignment
Why is that? Consider that A() is located in other file than main.