gpt4 book ai didi

python - 使用文件的python打印语句中的无效语法错误

转载 作者:太空宇宙 更新时间:2023-11-04 03:48:54 25 4
gpt4 key购买 nike

print('Group output sizes: |A| = {}, |B| = {}'.format(len(A),len(B)),    file=stderr)
^
SyntaxError: invalid syntax

任何人都可以帮助这个错误是什么?我最初认为这是因为打印语法,但我认为不是。

请帮忙。

最佳答案

您似乎正在尝试使用 Python 3.x 的 print Python 2.x 中的函数。为此,您需要先从 __future__ 导入 print_function :

将以下行放在源文件的最顶部,在任何注释和/或文档字符串之后:

from __future__ import print_function

下面是一个演示:

>>> # Python 2.x interpreter session
...
>>> print('a', 'b', sep=',')
File "<stdin>", line 1
print('a', 'b', sep=',')
^
SyntaxError: invalid syntax
>>>


>>> # Another Python 2.x interpreter session
...
>>> from __future__ import print_function
>>> print('a', 'b', sep=',')
a,b
>>>

关于python - 使用文件的python打印语句中的无效语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22310843/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com