For variables outside loop causes exception

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gordon Williams

    For variables outside loop causes exception

    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(epoch Data):
    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)
    UnboundLocalErr or: 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




  • Tim Roberts

    #2
    Re: For variables outside loop causes exception

    "Gordon Williams" <g_will@cyberus .ca> wrote:[color=blue]
    >
    >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(epoch Data):
    > 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)
    >UnboundLocalEr ror: local variable 'i' referenced before assignment
    >
    >What is the problem here? It appears that i has gone out of scope.[/color]

    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@probo.com
    Providenza & Boekelheide, Inc.

    Comment

    Working...