【问题标题】:SyntaxError: invalid syntax for print(file=saveto, *args, **kwargs)SyntaxError:打印的语法无效(file=saveto,*args,**kwargs)
【发布时间】:2018-09-20 07:27:07
【问题描述】:

我正在关注这个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 是干什么用的。请给我一些见解,谢谢。

【问题讨论】:

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


【解决方案1】:

print在Python 2中是一条语句,在Python 3中才成为函数,但是如果你想在Python 2中作为函数使用,可以添加:

from __future__ import print_function

在使用print 函数之前。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-29
    • 2017-11-04
    • 1970-01-01
    • 2015-09-08
    • 2013-08-04
    • 2017-04-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多