使用Python源代码中的utf-8编码$ cat bla.py
u = unicode('d…')s = u.encode('utf-8')print s
$ python bla.py
File "bla.py", line 1SyntaxError: Non-ASCII character '\xe2' in file bla.py on line 1, but no encoding declared;
see http://www.python.org/peps/pep-0263.html for details如何在源代码中声明utf-8字符串?
3 回答
慕码人8056858
TA贡献1803条经验 获得超6个赞
#!/usr/bin/env python# -*- coding: utf-8 -*-....
#!/usr/bin/env python# -*- coding: utf-8 -*-u = 'idzie wąż wąską dróżką'uu = u.decode('utf8')s = uu.encode('cp1250')print(s)
UTF-8
添加回答
举报
0/150
提交
取消