docs/library: Warn that ustruct doesn't handle spaces in format strings.
And also add a test to capture the CPython difference.
This commit is contained in:
parent
d934f8c8a8
commit
c1f74b3005
|
@ -12,6 +12,11 @@ Supported format codes: ``b``, ``B``, ``h``, ``H``, ``i``, ``I``, ``l``,
|
||||||
``L``, ``q``, ``Q``, ``s``, ``P``, ``f``, ``d`` (the latter 2 depending
|
``L``, ``q``, ``Q``, ``s``, ``P``, ``f``, ``d`` (the latter 2 depending
|
||||||
on the floating-point support).
|
on the floating-point support).
|
||||||
|
|
||||||
|
.. admonition:: Difference to CPython
|
||||||
|
:class: attention
|
||||||
|
|
||||||
|
Whitespace is not supported in format strings.
|
||||||
|
|
||||||
Functions
|
Functions
|
||||||
---------
|
---------
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
"""
|
||||||
|
categories: Modules,struct
|
||||||
|
description: Struct pack with whitespace in format, whitespace ignored by CPython, error on uPy
|
||||||
|
cause: MicroPython is optimised for code size.
|
||||||
|
workaround: Don't use spaces in format strings.
|
||||||
|
"""
|
||||||
|
import struct
|
||||||
|
|
||||||
|
try:
|
||||||
|
print(struct.pack('b b', 1, 2))
|
||||||
|
print('Should have worked')
|
||||||
|
except:
|
||||||
|
print('struct.error')
|
Loading…
Reference in New Issue