【发布时间】:2017-07-12 03:58:06
【问题描述】:
我有一个函数:
def push(push):
ser.write(push + '\r')
pull = ser.read(11)
return pull
我这样称呼它:
out = push("ka " + dp_id + " ff")
事实证明,python2 可以很好地工作,但是当我使用 python 3 时,我得到了错误:
不支持unicode字符串,请编码为字节:'ka 01 ff\r'
现在如果我这样做:
out = push(b"ka " + display_id + " ff")
我得到错误:
无法将字节连接到 str
我很困惑。有什么帮助?
【问题讨论】:
标签: python string python-3.x type-conversion