SyntaxError:print的语法无效(文件= saveto,* args,** kwargs)

时间:2018-09-20 07:27:07

标签: python syntax-error python-2.x rouge

我正在遵循此repo来安装files2rouge,然后出现如下错误:

Traceback (most recent call last):
  File "setup_rouge.py", line 7, in <module>
    from files2rouge import settings
  File "/home/cerdas/files2rouge/files2rouge/__init__.py", line 2, in <module>
    from files2rouge.files2rouge import main
  File "/home/cerdas/files2rouge/files2rouge/files2rouge.py", line 17, in <module>
    from files2rouge import utils
  File "/home/cerdas/files2rouge/files2rouge/utils.py", line 16
    print(file=saveto, *args, **kwargs)
              ^
SyntaxError: invalid syntax

以下是遇到错误的代码行:

def tee(saveto, *args, **kwargs):
    """Mimic the tee command, write on both stdout and file
    """
    print(args, kwargs)
    if saveto is not None:
        print(file=saveto, *args, **kwargs)

我不知道出了什么问题,也不确定saveto的作用是什么。请给我一些见识,谢谢。

1 个答案:

答案 0 :(得分:0)

print是Python 2中的一条语句,仅在Python 3中成为函数,但是如果要在Python 2中将其用作函数,则可以添加:

from __future__ import print_function

在使用print函数之前。

相关问题