For variables outside loop causes exception

G

Gordon Williams

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 = obsData[3]
Xs = 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
 
T

Tim Roberts

Gordon Williams said:
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 = obsData[3]
Xs = 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,169
Messages
2,570,915
Members
47,456
Latest member
JavierWalp

Latest Threads

Top