19. micropython module
Access and control MicroPython internals.
Some useful functions from the micropython module are below.
19.1. mem_info
- micropython.mem_info([verbose])
Print information about the memory currently being used. If
verboseis given, extra information is printed.
Use the REPL to see the printout.
from microbit import *
import micropython
micropython.mem_info()
19.2. const
- micropython.const(expr)
Mark a value as a constant that will not change. MicroPython can then substitute the value directly into the code, which saves memory. Constant names are usually written in capitals.
from microbit import *
from micropython import const
DELAY = const(500)
while True:
display.show(Image.HEART)
sleep(DELAY)
display.show(Image.HEART_SMALL)
sleep(DELAY)
19.3. opt_level
- micropython.opt_level([level])
Set or get the optimisation level used when compiling scripts. Called with no argument, it returns the current level.
from microbit import *
import micropython
# print(micropython.opt_level())
display.scroll(str(micropython.opt_level()), delay=80)