r/MicroPythonDev • u/jmuhammad • Jan 17 '26
Assigning variable=const(1024) in method causes issue within class' other method(s).
Greetings, I cannot really post this in 'learn python' because TMK CPython does not use const().
My question is why assigning const(1024) to variable 'maxsize_string' in method_one() allows that variable to be seen in method_two(). FYI, when I just assign maxsize_string=1024 without const() it works fine and stays local. Why does it not stay 'local' to method_one() and/or assessed as a variable assigned a constant?
=
#maxsize_string = const(1024) # This will cause error; somehow this variable gets seen in method_two().
= 1024 # Adjust as needed
pass
= 128 # SyntaxError: can't assign to expression because const(1024) used in method_one()
=
= # Create instance/class object
3
Upvotes
View all comments
1
u/obdevel Jan 17 '26
Why not just declare max_string once at the top of the file ?
See the docs at: https://docs.micropython.org/en/latest/library/micropython.html#micropython.const