Created
September 8, 2011 01:38
-
-
Save sonkm3/1202394 to your computer and use it in GitHub Desktop.
python unicode and string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# 文字列型にマルチバイト文字を入れる(この場合はソースコードの文字コードのutf-8のはず) | |
string = 'あいう' | |
# 文字列をutf-8とみなしてユニコード文字列に変換する | |
unicode_string = string.decode('utf-8') | |
# 文字列をそのまま出力する | |
print string | |
# ユニコード文字列をそのまま出力する | |
print unicode_string | |
# ユニコード文字列をutf-8に変換して出力する | |
print unicode_string.encode('utf-8') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment