Can't make static local variable work
Posted: Sun Dec 05, 2021 8:00 pm
I have this simple test code that runs on PC Python just fine but produces error on MP:
On PC:
On MP (ESP32 port 1.17):
If I attempt to define this static local variable outside the function:
So how do I use static local variable in MP? Is it a supported feature?
Code: Select all
def test_local():
if not hasattr(test_local, "myVar"):
test_local.myVar = 10
print(test_local.myVar)
Code: Select all
>>> test_local()
10
Code: Select all
>>> test_local()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in test_local
AttributeError: 'function' object has no attribute 'myVar'
Code: Select all
>>> test_local.myVar=5
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'function' object has no attribute 'myVar'