For variables outside loop causes exception

Gordon Williams g_will at cyberus.ca
Fri Oct 17 10:20:39 EDT 2003


Hi,

I have been using this code for a number of weeks without problems.  Now I
am getting an exception after the program has run a short while.  It has
already passed through this function several hundred time before the
exception.

The code in the function is (exactly as shown):

    for i, obsData in enumerate(epochData):
        Pcor[i] = obsData[3]
        Xs[i] = obsData[4]

    Asub, Lsub= Solve_all.model_matrix(Xs[:i+1], Pcor[:i+1],Xr)

The exception is:

    Asub, Lsub= Solve_all.model_matrix(Xs[:i+1], Pcor[:i+1],Xr)
UnboundLocalError: local variable 'i' referenced before assignment

What is the problem here?  It appears that i has gone out of scope.

Do variables i, obsData get destroyed when you leave the loop?  Is this
noted in the docs?  I didn't find it.

Does this have anything to do with enumeration?

Why has this worked this far without failing?

Regards,

Gordon Williams








More information about the Python-list mailing list