【问题标题】:SyntaxError: Non-UTF-8 code starting with '\xe2' in file {the location of the thing} line 138, but no encoding declared; see http://python.org/SyntaxError:在文件 {the location of the thing} 第 138 行中以 '\xe2' 开头的非 UTF-8 代码,但未声明编码;见 http://python.org/
【发布时间】:2020-11-09 01:41:12
【问题描述】:

我有一个名为引号的列表,其中包含很多 JoJo 引号,当我尝试执行时出现该错误。当我将所有的 ' 更改为 "。

quotes = ['Perhaps… Perhaps the time he foretold has come. If this is my destiny, I accept it. - Zeppeli', 'You truly are the lowest scum in history. You can’t pay back what you owe with money. - Jotaro Kujo', 'Impossible? We did a lot of impossible things on this journey. I’m tired of hearing that things are impossible or useless. Those words mean nothing to us. - Jotaro Kujo', 'Shoot me if you want to! But you better be prepared to face the consequences. The moment you try to pull that trigger, I’ll snap your fingers in half like matchsticks! - Joseph Joestar', 'would you be able to pull of a command that randomly generates a jojo quote when you use it - kirbs', 'What? The loser is evil? Well, in that case… you’re the evil one after all! The one who will be the judge is my Stand! - Jotaro Kujo', 'You’re god damn right! Everything worked out according to the plan… From the very beginning! (I just got lucky, but thinking I outsmarted him will drive Kars nuts). - Joseph Joestar', 'You’ve got to say something more like this before you get revenge. My name is Jean-Pierre Polnareff. For my sister’s honor, and so that my friend Avdol can rest in peace... Im going to hurl you into the depths of despair! - Jean-Pierre Polnareff', 'The ultimate being embodies the powers of each and every living thing, all lives gather as one. And… How beautiful it shines! Truly the most wonderful thing I have ever beheld… I have finally, finally tamed the sun! - Kars', 'I shall give you a chance. Go down two steps and I’ll let you join my side again. But if you rather die, then climb those stairs. - Dio Brando' 'KONO DIO DA! - Dio  Brando', 'I, Giorno Giovanna, have a dream. - Polpo', 'What did you say? Depending on your answer, I may have to kick your ass! - Joseph Joestar']

【问题讨论】:

  • 这是 python 3.x 吗?您的编辑器是否保存在 utf-8 中?您应该能够将其修剪为演示问题的几行程序。很可能您使用的是 Windows 代码页编码,而违规字符是 "…"。它对我们有用,因为您粘贴到 SO 中的是 utf-8。您可以将该字符粘贴到编辑器中并保存。然后print(open('mytestfile', 'rb').read())。如果那是单个字符,则您正在使用代码页。如果是b'\xe2\x80\xa6',那么你有 utf-8。
  • 你用的是哪个版本的python?
  • 我使用的是 Python 3.8 或 3.7,我忘记了哪个,我使用的是 sublime text。我还删除了所有“...”的字符,因为是的,它们是一个字符,并将它们更改为 2 个点,但没有任何变化。还是一样的错误

标签: python url-rewriting discord discord.py discord.py-rewrite


【解决方案1】:

这不是代码问题。使用更好的 IDE 来编辑您的 Python 代码

如果您使用的是 Notepad++,请点击顶部的编码并选择以 UTF-8 编码。

如果没有,则执行以下命令检查您的语言环境编码:

import locale
print(locale.getpreferredencoding())

如果未显示 UTF-8,则将 Sublime Text 中的 env 变量设置为:

"env": {"PYTHONIOENCODING": "utf-8", "LANG": "en_US.UTF-8"},

对于 python,通过Tools->Build System->New Build System

【讨论】:

  • 我同意它的 OP 编辑​​器很可能没有保存为 utf-8。但添加编码语句无济于事。
  • 我正在使用 Sublime 文本。我有完全相同的语句,除了我的代码中有不同的单词并且没有错误。这个特别有错误。
  • 呃是的,它太长了
  • 请检查此代码import locale print(locale.getpreferredencoding()),如果它不显示 UTF-8,则设置您的语言环境的 env 变量。
  • 请查看online
猜你喜欢
  • 2022-01-25
  • 2022-08-02
  • 1970-01-01
  • 2023-03-29
  • 2018-05-03
  • 2023-04-01
  • 1970-01-01
  • 2014-05-30
  • 1970-01-01
相关资源
最近更新 更多