特殊字符串在类和控制台中的操作不同
我输入
config = {}
config['x'] = ["vision","unknown","SCH-i569","harmony","中国移动"]
没问题python控制台可以处理它
但是当我在类init函数中编写相同的代码时,它会出现一些编码问题,
class Profile(object):
def __init__(self):
attributes = []
attributes.append('8')
attributes.append('htc')
config = {}
config['x'] = ["vision","unknown","SCH-i569","harmony","中国移动"]
print config['x']
attributes.append(config['x'])
self.attributes = attributes
def getAttributes(self):
return self.attributes
它会出现一个问题:
File "<stdin>", line 7
SyntaxError: (unicode error) 'utf8' codec can't decode byte 0xd6 in position 0: invalid continuation byte
当我删除“中国移动”
时,类工作。我不知道为什么一个班级和其他班级之间有不同
I input
config = {}
config['x'] = ["vision","unknown","SCH-i569","harmony","中国移动"]
is ok. The python console can handle it
But when I write the same code in a class init function,it occurs some encode problems
class Profile(object):
def __init__(self):
attributes = []
attributes.append('8')
attributes.append('htc')
config = {}
config['x'] = ["vision","unknown","SCH-i569","harmony","中国移动"]
print config['x']
attributes.append(config['x'])
self.attributes = attributes
def getAttributes(self):
return self.attributes
it occurs a problem:
File "<stdin>", line 7
SyntaxError: (unicode error) 'utf8' codec can't decode byte 0xd6 in position 0: invalid continuation byte
when I delete the "中国移动"
, the class work. I don't know why it is different between a class and other
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将
#-*-coding:utf-8-*-
添加到源文件中。http://www.python.org/dev/peps/pep-0263/
Add
#-*-coding:utf-8-*-
to your source file.http://www.python.org/dev/peps/pep-0263/