Python SyntaxError: non-ASCII character '\ xe2' in file

I just switched from using a Django application under Python 3 to using Python 2.7. Now I get this error:

SyntaxError: Non-ASCII character '\xe2' in file /Users/user/Documents/workspace/testpro/testpro/apps/common/models/vendor.py on line 9, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

The code referencing it is just a comment:

class Vendor(BaseModel):
    """
    A company manages owns one of more stores.โ€Ž
    """
    name = models.CharField(max_length=255)


    def __unicode__(self):
        return self.name

Why?

It works:

 class Vendor(BaseModel):
        """

        """
        name = models.CharField(max_length=255)


        def __unicode__(self):
            return self.name
+4
source share
1 answer

You have UTF-8 encoded by U + 200E LEFT-TO-RIGHT MARK in your documentation:

'\n    A company manages owns one of more stores.\xe2\x80\x8e\n    '

Either remove this code (and try using a code editor rather than a word processor) for your code, or just put the PEP-263 encoding comment at the top of the file:

# encoding=utf8

Python 3 UTF-8 , Python 2 ASCII , .

+8

Source: https://habr.com/ru/post/1543849/


All Articles