local variable referenced before assignment

Pete Bartonly none at try.invalid
Thu Oct 25 12:11:16 EDT 2007


Pete Bartonly wrote:
> 
> Quick question, probably quite a simple matter. Take the follow start of 
> a method:
> 
> 
> def review(filesNeedingReview):
> 
>     for item in filesNeedingReview:
>         (tightestOwner, logMsg) = item
> 
>         if (logMsg != None):
>             for logInfo in logMsg.changed_paths:
> 
> 
> This generates the error:
> 
>   UnboundLocalError: local variable 'logMsg' referenced before assignment
> 
> I thought I'd assigned it in the "(tightestOwner, logMsg) = item" line - 
> so in the python interpreter complaining about the fact this assignment 
> might not go well?
> 
> Thanks!

Argh! Mea culpa everyone!
Turns out that there is a similar few lines of code later on in the 
code. I was confusing which was which. (I was using meta-x goto-line but 
then looking at the wrong but somehow, as it appeared on the same screen 
in emacs.)
So the error was occuring at a similar line in the code, but one at 
whihc logMsg *wasn't* being set beforehand.

Sorry all, thanks for your help, appreciate it!
Pete




More information about the Python-list mailing list