试图在 python 不受支持的版本上使用海象运算符

Tried to use the walrus operator on a unsupported version of python

所以这在我的电脑 运行 v3.8.5 上有效,但在我的 python v3.7.3 电脑上它会抛出语法错误并指向“:=”作为错误。

ls = ['hi', 'hello', 'bye', 'goodbye', 'adios']

for i in (t := tqdm(ls, ncols=103, leave=False, ascii=' #')):
    t.set_description(i)
    sleep(1)

我知道我能做到

t = tqdm(ls, ncols=103, leave=False, ascii=' #')

for i in t:
    t.set_description(i)
    sleep(1)

但宁愿不...知道问题出在哪里吗?两台机器都是 运行 相同版本的 tqdm。

海象运算符是 Python 3.8 中的新增功能。参见 PEP 572:

https://www.python.org/dev/peps/pep-0572/