I'm running into an unbound local error message that I am not understanding. I am setting the default value of a variable to None (just so it is initialized) then in the next function, I run an if statement to check if it is still None, or if I have assigned it something else, and that is when I am getting the error. Please see the code below. Any help would be good.
from sys import stdout
restore_out = None
def toggle_out (toggle=1):
if toggle == 0:
if restore_out == None:
restore_out = stdout
stdout = None
elif toggle == 1 and restore_out != None:
stdout = restore_out
I'm using this to toggle standard output, so when I run a command with os.system('some command') that there is no output.
The code is supposed to call toggle_out(0) to turn it off, and toggle_out(1) to re-enable it.
Please let me know if anything comes to mind.