python - 来自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
解决方案
print()
是 Python 3 中的一个函数,不是语法的一部分。这就是为什么你需要括号。
推荐阅读
- c# - 远程服务器返回错误:(400) 错误请求。(从 WCF 到 ASP.NET)
- polymer - 如何在组件之间共享异步方法 - LitElement
- android - 有没有办法在后台每 15 分钟运行一次服务?
- java - 如何通过外部 API 或命令提示符调用 eclipse 插件?
- swift - MapView 在运行时变为 nil
- javascript - TypeError:第一个参数必须是 string、Buffer、ArrayBuffer、Array 或 Array-like Object 类型之一。在cryptoJS中接收到类型对象
- python-3.x - 这个链表插入实现是如何工作的?
- javascript - 当我使用 jQuery ddSlick JS 选择一个选项时,页面不断加载
- sql - 在表格的每个字段和字段中的每个字符之间插入分隔符
- google-apps-script - 尝试通过高级日历服务更新事件颜色时出现“对象不允许”错误