gpt4 book ai didi

python - 在 python IDE 上正确运行的 linux 终端中运行的 python 应用程序的错误输出

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:27:21 25 4
gpt4 key购买 nike

我有一个可以在 Python IDE 上完美运行的 Python 应用程序。它与外部设备进行串行通信。

import serial, string
port = serial.Serial("/dev/ttyUSB0", 38400, timeout=10.0)
serial.PARITY_NONE
serial.EIGHTBITS
serial.STOPBITS_ONE


#Set Rotor size

port.write(bytes([53, 4, 36, 0, 83]))
print("Set Rotor size")
data = port.read(20)
data1= list(data)
print(data1)

我得到以下正确的输出

Set Rotor size
[53, 1, 4, 0, 83, 53, 27, 0, 132, 83]

但是当我尝试在 linux 终端中运行时,我得到了不同的输出,这是错误的。

pi@raspberrypi /home/python $ python serialcomm.py
Set Rotor Size
['[', '5', '3', '\xff', ' ', ',', ' ', '8', '3', ']', ',', ' ', '8', '\xff', ']' , ',', '\x1b', '\x01', '\x84', ']']

最佳答案

我使用的是 python 3 IDE 来运行脚本。而在 Linux 中,默认版本是 python 2。

我可以使用命令行获得正确的输出

    pi@raspberrypi /home/python $ python3 serialcomm.py

关于python - 在 python IDE 上正确运行的 linux 终端中运行的 python 应用程序的错误输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32739802/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com