python - SyntaxError:打印的语法无效(file=saveto,*args,**kwargs)
问题描述
我正在关注这个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
。请给我一些见解,谢谢。
解决方案
print
在 Python 2 中是一个语句,在 Python 3 中才成为一个函数,但是如果你想在 Python 2 中将它用作一个函数,你可以添加:
from __future__ import print_function
在使用该print
功能之前。
推荐阅读
- android - Long amount of time elapses before onServiceConnected() is called
- c++ - 示例程序崩溃
- azure - 如何在 Microsoft Chatbot 服务中设置问候语
- html - html宽度导致滚动条
- python-3.x - 正方体错误
- java - 什么原因导致 EXCEPTION_ACCESS_VIOLATION 以及如何解决?
- cmake - CMake 的 execute_process 没有设置任何变量
- apache-spark - Spark 作业中止 - 在日志中找不到原因
- javascript - 认证 React JS 时出错
- git - SSH 检查成功但仍然无法克隆 git repo