<< 不支持的操作数类型:'str' 和 'int' Python 的奇怪行为(远程)

unsupported operand type(s) for <<: 'str' and 'int' strange behaviour of Python (Remote)

我看到很多帖子都有这个错误,但我的似乎真的很奇怪。我有远程解释器,所以我在 windows 和 Pycharm 上工作,它与我的 Raspberry pi3 相连。奇怪的是,如果我通过 pycharm 运行 代码,它就像魅力一样工作,但如果我去覆盆子控制台并在这里尝试将午餐脚本作为 sudo python mycode.py 它给了我这个错误

  unsupported operand type(s) for <<: 'str' and 'int'

所以我有两种方式使用相同的代码,但我得到了不同的结果。什么会导致它以及如何对抗它?

出现错误的代码:

v = ((bytes_arr[k] << 24) & 0xFF000000) | ((bytes_arr[k+1] << 16) & 0xFF0000) | \
            ((bytes_arr[k+2] << 8) & 0xFF00) | (bytes_arr[k+3] & 0xFF)

RPi 有时会使用与我们想象的不同的 python 版本尝试 运行 将其设为 sudo python3 mycode.py