c737cde947
Anywhere a module is mentioned, use its "non-u" name for consistency. The "import module" vs "import umodule" is something of a FAQ, and this commit intends to help clear that up. As a first approximation MicroPython is Python, and so imports should work the same as Python and use the same name, to a first approximation. The u-version of a module is a detail that can be learned later on, when the user wants to understand more and have finer control over importing. Existing Python code should just work, as much as it is possible to do that within the constraints of embedded systems, and the MicroPython documentation should match the idiomatic way to write Python code. With universal weak links for modules (via MICROPY_MODULE_WEAK_LINKS) users can consistently use "import foo" across all ports (with the exception of the minimal ports). And the ability to override/extend via "foo.py" continues to work well. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
48 lines
1.5 KiB
ReStructuredText
48 lines
1.5 KiB
ReStructuredText
:mod:`struct` -- pack and unpack primitive data types
|
|
=====================================================
|
|
|
|
.. module:: struct
|
|
:synopsis: pack and unpack primitive data types
|
|
|
|
|see_cpython_module| :mod:`python:struct`.
|
|
|
|
Supported size/byte order prefixes: ``@``, ``<``, ``>``, ``!``.
|
|
|
|
Supported format codes: ``b``, ``B``, ``h``, ``H``, ``i``, ``I``, ``l``,
|
|
``L``, ``q``, ``Q``, ``s``, ``P``, ``f``, ``d`` (the latter 2 depending
|
|
on the floating-point support).
|
|
|
|
.. admonition:: Difference to CPython
|
|
:class: attention
|
|
|
|
Whitespace is not supported in format strings.
|
|
|
|
Functions
|
|
---------
|
|
|
|
.. function:: calcsize(fmt)
|
|
|
|
Return the number of bytes needed to store the given *fmt*.
|
|
|
|
.. function:: pack(fmt, v1, v2, ...)
|
|
|
|
Pack the values *v1*, *v2*, ... according to the format string *fmt*.
|
|
The return value is a bytes object encoding the values.
|
|
|
|
.. function:: pack_into(fmt, buffer, offset, v1, v2, ...)
|
|
|
|
Pack the values *v1*, *v2*, ... according to the format string *fmt*
|
|
into a *buffer* starting at *offset*. *offset* may be negative to count
|
|
from the end of *buffer*.
|
|
|
|
.. function:: unpack(fmt, data)
|
|
|
|
Unpack from the *data* according to the format string *fmt*.
|
|
The return value is a tuple of the unpacked values.
|
|
|
|
.. function:: unpack_from(fmt, data, offset=0, /)
|
|
|
|
Unpack from the *data* starting at *offset* according to the format string
|
|
*fmt*. *offset* may be negative to count from the end of *buffer*. The return
|
|
value is a tuple of the unpacked values.
|