SyntaxError: Non-UTF-8 code starting with '\x91'

后端 未结 4 928
走了就别回头了
走了就别回头了 2020-11-28 14:49

I am trying to write a binary search program for a class, and I am pretty sure that my logic is right, but I keep getting a non-UTF-8 error. I have never seen this error and

相关标签:
4条回答
  • 2020-11-28 14:54

    Your editor replaced ' (ASCII 39) with U+2018 LEFT SINGLE QUOTATION MARK characters, usually a sign you used Word or a similar wordprocessor instead of a plain text editor; a word processor tries to make your text 'prettier' and auto-replaces things like simple quotes with fancy ones. This was then saved in the Windows 1252 codepage encoding, where the fancy quotes were saved as hex 91 characters.

    Python is having none of it. It wants source code saved in UTF-8 and using ' or " for quotation marks. Use notepad, or better still, IDLE to edit your Python code instead.

    You have numerous other errors in your code; you cannot use spaces in your variable names, for example, and Python uses and, not & as the boolean AND operator. != is an operator requiring 2 operands (it means 'not equal', the opposite of ==), the boolean NOT operator is called not.

    0 讨论(0)
  • 2020-11-28 14:54

    If you're using Notepad++, click Encoding at the top and choose Encode in UTF-8.

    0 讨论(0)
  • 2020-11-28 14:56

    The character you are beginning your constant strings with is not the right string delimiter. You are using

    ‘Ava Fischer’   # ‘ and ’ as string delimiters
    

    when it should have been either

    'Ava Fischer'   # Ascii 39 as string delimiter
    

    or maybe

    "Ava Fischer"   # Ascii 34 as string delimiter
    
    0 讨论(0)
  • 2020-11-28 15:04

    Add this line at the top of you code. It may work.

        # coding=utf8
    
    0 讨论(0)
提交回复
热议问题