python - 如何将python3程序转换成python2.7程序
问题描述
我用jetson nano board测试程序按照这条指令进行,可以在python3解释器上运行,但是在python2.7版本的解释器会提示错误,请问大家,怎么修改呢?
import time
import struct
from binascii import unhexlify
import binascii
import crcmod
import math
byte0 = b'\x01'
byte1 = b'\xEA'
DEC1 = int(100)
DEC2 = int(20)
byte2 =(struct.pack("i",DEC1)[-4:-3])#线速度
byte3 =(struct.pack("i",DEC1)[-3:-2])#线速度
# speed_vel = byte2 + byte3
byte4 = (struct.pack("i",DEC2)[-4:-3]) #角速度两个字节
byte5 = (struct.pack("i",DEC2)[-3:-2])
# speed_ang = byte4+byte5
byte_speed = byte2 + byte3 + byte4 + byte5
read = byte0 + byte1 + byte_speed #解析校验码要输入的前几位
read=(str(binascii.b2a_hex(read))[2:-1])
crc16 =crcmod.mkCrcFun(0x18005, rev=True, initCrc=0xFFFF, xorOut=0x0000)
data = read.replace(" ","")
readcrcout=hex(crc16(unhexlify(data))).upper()
print(readcrcout)
str_list = list(readcrcout)
if len(str_list) < 6:
str_list.insert(2, '0'*(6-len(str_list))) # 位数不足补0
crc_data = "".join(str_list)
#print(crc_data)
read = read.strip()+crc_data[4:]+crc_data[2:4]
read = bytes.fromhex(read)
speed_code = read
print('speed_code', speed_code)
解决方案
推荐阅读
- reactjs - React:自定义 Ref(没有 DOM)
- c++ - 如何使用 c++ win32 api 更改应用程序中不是我的菜单项的控件的标题?
- java - Maven 依赖不可用 | 存在于本地 .m2 存储库中 | 使用 Eclipse 构建
- firebase - 两个 Web 应用程序 - 一个 firebase 项目:我应该为一个应用程序创建两个应用程序还是两个托管站点?
- python - 如何在python中分离一些重叠的时间段?
- json - 如何让 Swift 派生指定类型来解码 JSON
- mysql - MySQL 显示截断和求和 NULL 值
- odoo - 如何在操作菜单 Odoo 12 中添加新按钮?
- c++ - 试图理解 int main c++ 中删除对象的行为
- python - 如何在 python 中使用 LIKE 函数与 slqite3 绑定(使用?)