variable scope

Bruno Desthuilliers bruno.desthuilliers at websiteburo.com
Thu Jan 18 17:05:21 CET 2007


gonzlobo a écrit :
> Greetings,
> I've been using Python to successfully parse files. When the entire
> program was smaller, the variable firstMsg worked fine, but now
> doesn't because it's used in function PID_MinMax. I know it's a result
> of variables and their scope.
> 
> I declare the variable 'firstMsg = 0' in the main loop, pass it to the
> function 'PID_MinMax(firstMsg, PID)'. When the function increments the
> variable, it doesn't pass it back to the main program. What am I doing
> wrong?
> 
> 
> ---- major snippage) ---
> firstMsg = 0
(snip)
> def PID_MinMax(firstMsg, PID):
(snip)
>    if firstMsg != 0:
      if firstMsg:
>        tDelta = tCurrent - pLast[idx]
>        if tDelta > pMax[idx]:
>            pMax[idx] = tDelta
>        if tDelta < pMin[idx]:
>            pMin[idx] = tDelta
>    elif firstMsg == 0:
      else:
>        firstMsg = 1
>    pLast[idx] = tCurrent
>    print pMin, pMax
>    return firstMsg

> ############## main ##############
(snip)
>         if PID in pPIDs:
>             PID_MinMax(firstMsg, PID)
               firstMsg = PID_MinMax(firstMsg, PID)

You're returning firstMsg from PID_MinMax, but discarding the value...



More information about the Python-list mailing list