首页 > 解决方案 > 来自bash的Python3无效语法

问题描述

我有一个我想从 bash 执行的 python 函数。使用 Python 2 它可以工作

$ python2 -c "import bech32; print bech32.bech32_create_checksum('tb', [0, 3] )"
[11, 18, 12, 1, 31, 6]

但我有一个 python3 的错误语法

$ python -c "import bech32; print bech32.bech32_create_checksum('tb', ['0, 3'] )" 
  File "<string>", line 1
    import bech32; print bech32.bech32_create_checksum('tb', ['0, 3'] )
                              ^
SyntaxError: invalid syntax

我的python版本是:

$ python --version
Python 3.7.7

标签: python

解决方案


print()是 Python 3 中的一个函数,不是语法的一部分。这就是为什么你需要括号。


推荐阅读