Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On ubuntu14.04,Unicode issue. #25

Open
supergis opened this issue Aug 5, 2014 · 0 comments
Open

On ubuntu14.04,Unicode issue. #25

supergis opened this issue Aug 5, 2014 · 0 comments

Comments

@supergis
Copy link
Collaborator

supergis commented Aug 5, 2014

Ubuntu14.04, python 的Unicode有问题。
所有的字符串应加上u以避免问题,比如:
logging.info(u"创建数据集:[" + self.datasetName + u"]成功。")
对于变量,可使用如下方式转换成unicode:
unicode(datasetType,"ascii")

可参考:
1 #将Unicode转换成普通的Python字符串:"编码(encode)"

2 unicodestring = u"Hello world"

3 utf8string = unicodestring.encode("utf-8")

4 asciistring = unicodestring.encode("ascii")

5 isostring = unicodestring.encode("ISO-8859-1")

6 utf16string = unicodestring.encode("utf-16")

7

8

9 #将普通的Python字符串转换成Unicode: "解码(decode)"

10 plainstring1 = unicode(utf8string, "utf-8")

11 plainstring2 = unicode(asciistring, "ascii")

12 plainstring3 = unicode(isostring, "ISO-8859-1")

13 plainstring4 = unicode(utf16string, "utf-16")

14

15 assert plainstring1==plainstring2==plainstring3==plainstring4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant