I find this one entirely confounding. The below code runs fine:
def vendor(title, description):
def validate():
print("in validate, title: ", title)
print("in validate, description: ", description)
convert()
def convert():
print("\nin convert, title: ", title)
print("in convert, description: ", description)
if title == "fedex":
pass
#description = "something else"
validate()
vendor("ups", "stuff")
But substitute pass with a reassignment like description = "something else" and I get UnboundLocalError: local variable 'description' referenced before assignment. If I take out print("in convert, description: ", description) the program runs without error.
What gives? How am I referencing description before assignment? Also, it doesn't seem to matter if a pass vendor() "fedex" or something else like "ups" as the title, I still get the error message. How would I go about doing what I'm trying to do - reassign a variable (albeit a function parameter) if a certain condition is True?
Thanks in advance!