Python Convert String to Byte

后端 未结 2 1096
不知归路
不知归路 2021-01-19 10:52

I am trying to do some serial input and output operations, and one of those is to send an 8x8 array to an external device (Arduino). The pySerial library requires that the i

2条回答
  •  天涯浪人
    2021-01-19 11:07

    in Python 3.x, You can use bytes and str like below.

    >>> bytes('foo'.encode())
    b'foo'
    
    >>> a = bytes('foo'.encode())
    >>> str(a.decode())
    'foo'
    

提交回复
热议问题