Sep-24-2021, 04:37 PM
Hi all,
I'm working with a program that operates largely with functions. The functions are all defined at the top with the main program starting ~Line 400.
I'm having issues today with writing output to files. Yesterday it was working fine. I'm not sure what I did.
Soooo... trying to debug. One thing I want to do is add test_counter to be +=1 every time Python starts going through a function to make sure the function is actually being called. At the end of the main program, I print test_counter to see the total (hoping for a nonzero number).
At the very top of the program, I added:
UnboundLocalError: local variable 'test_counter' referenced before assignment
So instead, at the top I tried:
Any thoughts?
Mark
I'm working with a program that operates largely with functions. The functions are all defined at the top with the main program starting ~Line 400.
I'm having issues today with writing output to files. Yesterday it was working fine. I'm not sure what I did.
Soooo... trying to debug. One thing I want to do is add test_counter to be +=1 every time Python starts going through a function to make sure the function is actually being called. At the end of the main program, I print test_counter to see the total (hoping for a nonzero number).
At the very top of the program, I added:
test_counter = 0How best to proceed, now, with regard to local and global variables? My thought was that since I defined this as part of the main program (not inside any functions), it will be accessible to all inside or outside functions. Unfortunately, I just got:
UnboundLocalError: local variable 'test_counter' referenced before assignment
So instead, at the top I tried:
global test_counter test_counter = 0Same error.
Any thoughts?
Mark