[Microbit-Python] Image to string and back again

Matt Hickford matt.hickford at gmail.com
Thu Jan 5 16:40:37 EST 2017


Hi all. I wrote a program using the radio module to send images between
microbits, but hit a snag converting the received string back to an Image.

To demonstrate the problem:

    >>> Image(str(Image.DUCK))

    Traceback (most recent call last):

    File "<stdin>", line 1, in <module>

    ValueError: Unexpected character in Image definition.

In the end, the solution was to send `repr(image)[7:36]` rather than
`str(image)`, which felt less obvious than ideal.

Could the Image(string) constructor be improved to strip the extraneous
characters? Otherwise perhaps a note should go in the documentation [1]?

-Matt

[1] https://microbit-micropython.readthedocs.io/en/
latest/image.html#microbit.Image
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/microbit/attachments/20170105/5e65c547/attachment.html>


More information about the Microbit mailing list