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

标签 python linux terminal ide serial-port

我有一个可以在 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/

相关文章:

python - Pandas :应用生成列表的操作不可调用

Python3.6函数未调用

linux - Ansible playbook 上的 "When"条件无法使用运算符按预期工作

linux - 为性能标准编写 bash 代码

bash - 使用转义序列呈现文本(如终端)

linux - "Bad File Descriptor"异常因为使用nohup

python - 带有整数参数的 Optparse

python - pypy pickled 不能被 cpython unpickled

c++ - 在 Linux 上执行二进制文件时找不到与 CMake 链接的 OGRE 3D 共享库

c -/usr/bin/xfce4-terminal 的执行给出 "Session manager variable not defined"