小编Ste*_*dar的帖子

什么是unicode字符串?

什么是unicode字符串?

常规字符串和unicode字符串之间有什么区别?

什么是utf-8?

我正在尝试学习Python,我一直听到这个流行语.下面的代码是做什么的?

i18n字符串(Unicode)

> ustring = u'A unicode \u018e string \xf1'
> ustring
u'A unicode \u018e string \xf1'

## (ustring from above contains a unicode string)
> s = ustring.encode('utf-8')
> s
'A unicode \xc6\x8e string \xc3\xb1'  ## bytes of utf-8 encoding
> t = unicode(s, 'utf-8')             ## Convert bytes back to a unicode string
> t == ustring                      ## It's the same as the original, yay!
True
Run Code Online (Sandbox Code Playgroud)

文件Unicode

import codecs

f = codecs.open('foo.txt', 'rU', 'utf-8')
for line …
Run Code Online (Sandbox Code Playgroud)

python unicode utf-8

26
推荐指数
1
解决办法
6万
查看次数

标签 统计

python ×1

unicode ×1

utf-8 ×1