Prints e strings dando erro

Prints e strings dando erro

by Matheus Cassiano -
Number of replies: 1

Enquanto que fazendo as chamadas:

>>> t1 = Token("+",OPERADOR)
>>> str(t1)
"O('+')"
>>> print(t1)
O('+')

sai tudo direitinho, ao fazer

>>> lista = tokeniza("+")
>>> imprima_tokens(lista)

tenho como resposta

Traceback (most recent call last):
File "<pyshell#72>", line 1, in <module>
print(lista[0])
File "C:\Users\matheus.cunha.CEC\Desktop\esqueleto_tokeniza.py", line 211, in __str__
return texto
UnboundLocalError: local variable 'texto' referenced before assignment

 

("texto" é o nome da variável que recebe as strings no método __str__ )

 

Algum help, please?

In reply to Matheus Cassiano

Re: Prints e strings dando erro

by José Coelho de Pina -

A mensagem de erro diz que na linha 211 do método __str__() a variável texto foi usada ser ter sido criada.

Traceback (most recent call last):
File "<pyshell#72>", line 1, in 
print(lista[0])
File "C:\Users\matheus.cunha.CEC\Desktop\esqueleto_tokeniza.py", line 211, in __str__
return texto
UnboundLocalError: local variable 'texto' referenced before assignment