相关疑难解决方法(0)

SyntaxError:函数返回'£'时文件中的非ASCII字符'\ xa3'

说我有一个功能:

def NewFunction():
    return '£'
Run Code Online (Sandbox Code Playgroud)

我想在它前面打一些带有井号的东西,当我尝试运行这个程序时它会输出错误,显示以下错误信息:

SyntaxError: Non-ASCII character '\xa3' in file 'blah' but no encoding declared;
see http://www.python.org/peps/pep-0263.html for details
Run Code Online (Sandbox Code Playgroud)

谁能告诉我如何在返回功能中加入英镑符号?我基本上是在课堂上使用它,它'__str__'包含在包含英镑符号的部分内.

python unicode python-unicode

265
推荐指数
6
解决办法
34万
查看次数

SyntaxError:Unicode字符串中的编码声明

如果我尝试#coding=utf-8在文件顶部使用魔术评论,那么会发生以下情况:

Traceback (most recent call last):
  File <string>, line 0
SyntaxError: encoding declaration in Unicode string
Run Code Online (Sandbox Code Playgroud)

我真的没有做错任何事.这是代码:

#coding=utf-8

string = raw_input()
chars = {}
for i in string:
    if i in chars:
        chars[i] += 1
    else:
        chars[i] = 0
print chars
Run Code Online (Sandbox Code Playgroud)

我用repl.it.

python unicode encoding

1
推荐指数
1
解决办法
6137
查看次数

标签 统计

python ×2

unicode ×2

encoding ×1

python-unicode ×1