'Pyflakes reports an invalid syntax error in a print command

Pyflakes reports an invalid syntax error in a print (to file) command in a class method. Here is the code:

class Controller():
    def __init__(self):
        self.base_url = ''
        self.permissions = None
        self.url = ''
        self.description = ''
        self.requests = ''
        self.url_params = ''
        self.data = ''
        self.response = ''
        self.pagination = ''
        self.cmd_file = None
        self.json_file = None
        self.html_file = None
        self.dict_file = None
        self.app_name = ''
        self.app = None
    def json_doc(self):
        if self.permissions:
            permissions = self.permissions + '.'
        else:
            permissions = ''
        print(
            '{\n' \
            '\t"URL": "' + self.url + '",\n' \
            '\t"Description": "' + self.description + '.",\n' \
            '\t"Requests": "' + self.requests + '",\n' \
            '\t"Permissions": "' + permissions + '",\n' \
            '\t"URL Parameters": "' + self.url_params + '",\n' \
            '\t"Data": "' + self.data + '",\n' \
            '\t"Response": "' + self.response + '",\n' \
            '\t"Pagination": "' + self.pagination + '"\n' \
            '}', \
            file=self.json_file
        )

Here is the error:

curl_doc.py:79:17: invalid syntax
            file=self.json_file
                ^

json_file is set elsewhere in my code. It seems to be a problem with pyflakes as the code runs OK. The pyflakes command used was:

pyflakes curl_doc.py


Solution 1:[1]

remove that back slash here and you are fine:

'}', \
file=self.json_file

Solution 2:[2]

print("your name contains " + new_num_char + " characters".) i wrote the above code,and the error was syntax error , it took me about an hour to figure out that my fullstop was outside the quotes. so in my own opinion, pyflakes E syntax error actually mean syntax error; you just have to check your code again.

Solution 3:[3]

I updated Pyflakes from version 0.8.1 to version 1.2.3 and the problem went away:

pip install --upgrade pyflakes

Posted on behalf of the question asker

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 linqu
Solution 2 OFONITEX
Solution 3