I'm trying to access a variable inside a function that I've already tried making global, but that doesn't work. Here's my code (trimmed down with no unnecessary variable declarations):
global col
col = 0
def interpret(text):
for char in text:
col += 1
The error I get says:
Traceback (most recent call last):
File "main.py", line 156, in <module>
interpret(line) (Where I call the function in the rest of the code)
File "main.py", line 21 (5), in interpret
col += 1
UnboundLocalError: local variable 'col' referenced before assignment
How can I fix this?
global colshould be insideinterpret.