Post
by jimmo » Thu Aug 22, 2019 9:21 am
Hi,
The behaviour of __debug__ is a bit subtle. It's handled by the lexer, so when __debug__ appears in your code, MicroPython effectively replaces it with True or False depending on the current value -- before executing any code. So setting opt_level in the same script won't change the value in the current script.
The documentation says "If *level* is given then this function sets the optimisation level for subsequent compilation of scripts"
Every line that you execute in the REPL is a new compilation.
If you want opt_level to take effect for your main.py, set it in boot.py.