Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8374

MicroPython • Re: NameError: local variable referenced before assignment

$
0
0
Do that 'global' for every global variable you use in every functions. This is the Python way of globals.
Looks like it is becasue you cannot modify a global variable (on_off) inside a function without declaring it as global.

Code:

def motor_test() :    global on_off, rotation    ...    

Statistics: Posted by gmx — Sun Jan 25, 2026 6:45 pm



Viewing all articles
Browse latest Browse all 8374

Trending Articles