Mindboggling Scope Issue

Terry Reedy tjreedy at udel.edu
Sun Oct 24 21:09:40 EDT 2004


"James Stroud" <jstroud at mbi.ucla.edu> wrote in message 
news:200410241616.14515.jstroud at mbi.ucla.edu...
>  File "./passerby", line 1378, in ok
>    print result
> UnboundLocalError: local variable 'result' referenced before assignment

      def ok():
        # different : GETS ERROR!
        print result
        pw = passEntry.get()
        if len(pw):
          passWindow.result = pw
        passWindow.destroy()
---------------------

Based on the error traceback, I have to wonder: did the code you actually 
ran to get the error have 'result = pw' instead of 'passWindow = pw'?  The 
above looks like an intermediate version.  Otherwise, result is set to None 
two lines after this definition and never changed, which would not make 
much sense, nor would the error message make sense to me.

Terry J. Reedy






More information about the Python-list mailing list