SyntaxError: invalid syntax for print(file=saveto, *args, **kwargs)

1.9k views Asked by At

I was following this repo for installing files2rouge, then i got an error as below:

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

Here the line of code that encountered the error:

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)

I have no idea whats wrong, and not sure what is saveto for. Please give me some insight, thanks.

1

There are 1 answers

0
blhsing On

print is a statement in Python 2 and only becomes a function in Python 3, but if you want to use it as a function in Python 2, you can add:

from __future__ import print_function

before you use the print function.