For variables outside loop causes exception

Tim Roberts timr at probo.com
Sat Oct 18 23:43:19 EDT 2003


"Gordon Williams" <g_will at cyberus.ca> wrote:
>
>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.

The most likely problem is that epochData is empty.  If the range is empty,
the for variables do not get assigned.  You can check for that via "if not
epochData", if you need to.
-- 
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.




More information about the Python-list mailing list