Search code examples
pythonpylint

invalid syntax (<string>, line 4) (syntax-error)


I have an invalid syntax according to flake8, pylint, but the code works. What's wrong with that code?

I did lots of Google search but couldn't find anything.

#!/usr/bin/env python
with open("test.py", "a") as output:
    # E:  4, 0: invalid syntax (<string>, line 4) (syntax-error)
    print("hello world", file=output)

Solution

  • What version of Python are you running? I'm not sure when it was implemented exactly but I don't think earlier versions of Python had a file=output parameter for the print() function so your interpreter might only be expecting a string