Declare success_indicator as a local variable
Redo #313 on the correct branch. Declare success_indicator as a local variable, not a GLOBAL CONSTANT. * By convention, values that may change at runtime should not be in UPPERCASE. * A global variable can be read from either with or without a global statement * A global variable can be written to only when preceded by a global statement ```python >>> SUCCESS_INDICATOR = 0 >>> def read_from_global(): ... print(SUCCESS_INDICATOR) ... >>> def write_to_declared__global(): ... global SUCCESS_INDICATOR ... SUCCESS_INDICATOR += 1 ... >>> def write_to_undeclared__global(): ... SUCCESS_INDICATOR += 1 ... >>> read_from_global() 0 >>> write_to_declared__global() >>> read_from_global() 1 >>> write_to_undeclared__global() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 2, in write_to_undeclared__global UnboundLocalError: local variable 'SUCCESS_INDICATOR' referenced before assignment ```pull/314/head
parent
73ee2b7410
commit
fba648eac1
Loading…
Reference in New Issue