【问题标题】:Invalid Syntax issue in python stringpython字符串中的无效语法问题
【发布时间】:2021-02-27 13:36:47
【问题描述】:

我在 docker 容器上运行以下代码。当我在没有 docker 容器的情况下运行时,它工作得非常好,但是当我在 docker 容器上运行时,我收到无效的语法。 docker 容器上的 Python 版本是 3.5,而机器上的 Python 版本是 3.6

print(f"{time.strftime('%H:%M:%S')} ( i ) :  Switching to {current_server}...")

错误:

File "client.py", line 21
print(f"{time.strftime('%H:%M:%S')} ( i ) :  Switching to 
{current_server}...")
SyntaxError: invalid syntax

谢谢,非常感谢帮助,如何解决这个格式问题。

【问题讨论】:

  • 请包含错误堆栈跟踪

标签: python python-3.x python-3.5


【解决方案1】:

在 python 3.6 (https://www.python.org/dev/peps/pep-0498/) 中引入了 f-strings。因此,在 docker 中运行 Python 3.5 可能是您的问题的原因。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多