I understand that there exist numbers of posts about referenced before assignment with increments.
However, I see a similar issue with format string.
greeting = "hello, {}"
def printHello(name):
greet = greeting.format(name)
print(greet)
printHello("Erica")
I have local variable 'greet' referenced before assignment.
Can anyone explain why this is the case?
Also, this error occurs once in a while so it's not deterministic...
I assume global greeting will fix the issue?
== edited ==
I have found that the error was coming from one of the library not my code sorry for confusion
The problem here is that you have re-defined print and hence it is going in a recursion.
Changing the function name to something else, should solve the problem
greeting = "hello, {}"
def printHello(name):
greet = greeting.format(name)
print(greet)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With