!!! abstract "摘要"
- MicroPython 提供丰富的模块,每个模块提供特定的功能。了解开发的过程中一些常用的模块的使用方式,可以让你很好的使用 MicroPython 的功能。
- 这些模块可以通过 env 工具的 menuconfig 功能来开启和关闭,如果你需要使用特定的模块,在 menuconfig 中选中模块名,保存退出后,重新编译运行即可。
MicroPython 的模块(函数和类库)有以下几类 :
Note about the availability of modules and their contents: This documentation in general aspires to describe all modules and functions/classes which are implemented in MicroPython. However, MicroPython is highly configurable, and each port to a particular board/embedded system makes available only a subset of MicroPython libraries. For officially supported ports, there is an effort to either filter out non-applicable items, or mark individual descriptions with "Availability:" clauses describing which ports provide a given feature. With that in mind, please still be warned that some functions/classes in a module (or even the entire module) described in this documentation may be unavailable in a particular build of MicroPython on a particular board. The best place to find general information of the availability/non-availability of a particular feature is the "General Information" section which contains information pertaining to a specific port.
Beyond the built-in libraries described in this documentation, many more modules from the Python standard library, as well as further MicroPython extensions to it, can be found in the micropython-lib repository.
标准的 Python 库被 “微型化”后,就是 micropython 标准库。它们仅仅提供了该模块的核心功能。一些模块没有直接使用标准的 Python 的名字,而是冠以"u",例如ujson代替json。也就是说 micropython 标准库(=微型库),只实现了一部分模块功能。通过他们的名字不同,用户有选择的去写一个 Python 级模块扩展功能,也是为实现更好的兼容性。
在嵌入式平台上,可添加 Python 级别封装库从而实现命名兼容 CPython,微模块即可调用他们的 u-name,也可以调用 non-u-name。根据 non-u-name 包路径的文件可重写。
例如,import json的话,首先搜索一个json.py文件或json目录进行加载。如果没有找到,它回退到加载内置ujson模块。