您的位置:首页 > 编程语言 > Python开发

How to use UTF-8 in Python

2014-05-12 13:44 393 查看
http://stackoverflow.com/questions/6289474/working-with-utf-8-encoding-in-python-source

In source header you can declare:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
....


It is described in the PEP 0263:

Then you can use UTF-8 in strings:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

u = 'idzie wąż wąską dróżką'
uu = u.decode('utf8')
s = uu.encode('cp1250')
print(s)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: