The following is the Python2 code, send data to the serial port, how to change to Python3?

-sharp coding=utf-8
import serial

cmd = [0xa5, 0x00, 0x09, 0x0a, 0xcc, 0x33, 0xc3, 0x3c, 0xa6]

with serial.Serial("/dev/ttyAMA0", 115200, timeout=1) as ser:
    for i in cmd:
        k = chr(i)
        ser.write(k)
    s = ser.read(10)
    print(s)

since the bytes of Python3 is passed into str by Python2, why do I report an error after converting the last data to be sent into bytes in Python3?

May.24,2022

chr gets the integer type.
I always change the number to a hexadecimal string and then send the data. All are sent ['a5pm]. This kind of.
I don't know if there is a better way.

import binascii
cmd = [0xa5, 0x00, 0x09, 0x0a, 0xcc, 0x33, 0xc3, 0x3c, 0xa6]
with serial.Serial('/dev/ttyAMA0', 115200, timeout=1) as ser:
    for i in cmd:
        k = hex(i)[2:]
        if len(k) < 2: 
            k = '0' + k
        ser.write(binascii.a2b_hex(k))
    s = ser.read(10)
    print(s)

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e9c838-476c2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e9c838-476c2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?