variable scope

Bruno Desthuilliers bruno.desthuilliers at
Fri Jan 19 14:34:48 CET 2007

gonzlobo a écrit :
Please keep this on clpy...

> Sorry, but I don't understand. I *should* pass firstMsg to the
> function like I did (PID_MinMax(firstMsg)), correct?


> Then I should
> pass the variable back to the main loop by 'return firstMsg', correct?


Yes, you have to return the value from your function. But then, if you 
don't store this value somewhere, it's lost. What you have to understand 
is that you actually have *2* variables named 'firstMsg' : one in the 
'main loop', and one in PID_MinMax(). Rebinding the second name has no 
impact on the first. So you have to explicitely assign the return value 
of PID_MinMax() to the main loop's firstMsg variable. Else, this value 
is simply discarded.


More information about the Python-list mailing list