【发布时间】:2016-11-01 12:10:00
【问题描述】:
我收到以下错误:SyntaxError: Non-ASCII character '\x83' in file sound.wav on line 2, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
但是,我的代码中没有非 ascii 字符。这是我正在使用的代码:
import pygame
pygame.mixer.init()
pygame.mixer.music.load("sound.wav")
pygame.mixer.music.play()
while pygame.mixer.music.get_busy() == True:
continue
据我所知,第 2 行没有非 ascii 字符,没关系在整个脚本中。
我尝试将# -*- coding: utf-8 -*- 添加到文件顶部,但仍然出现相同的错误。
\x83 是一个'no break here' 字符,但是notepad++ 在选中'show all characters' 时不会显示这样的字符。
【问题讨论】:
-
错误信息说字符是in sound.wav。
-
但这是一个奇怪的错误(它当然是二进制文件,为什么它需要ASCII),不知道是什么原因造成的。
-
@RemcoGerlich 你说得对,这是一个奇怪的错误,我什至没有意识到它这么说。我重新启动了我的机器,现在我得到了另一个错误,即 pygame 无法读取 wav 文件,所以之前可能是混淆了。不知道为什么。