python - Got UnboundLocalError: Local Variable referenced before assignment, but it wasn't -
i stumped. looked @ other answers same question, none seemed give slightest answer why myself getting error. have pretty 2 of exact same programs running same code exception of url's , product id's reads files. programs little bit long, put them on pastebin here. don't expect read code, error occurs in main function define pid , try use later in function. why 1 work fine , other not? far can see same in part, maybe missed something! appreciated! thanks!
ps: error receive is:
unboundlocalerror: local variable 'pid' referenced before assignment
your findall('crc-start(.*?)crc-end', pidfile.read(), re.s) on line 202 didn't find anything, pid didn't declared, boom, unboundlocalerror.
this happens because python interpreter makes preliminary pass on code, marking encountered variables local, not (and cannot) check if code declares them executed. minimal reproducible example of effect this:
>>> def foo(): if 0: = 1 print >>> foo() traceback (most recent call last): file "<pyshell#5>", line 1, in <module> foo() file "<pyshell#4>", line 4, in foo print unboundlocalerror: local variable 'a' referenced before assignment
Comments
Post a Comment