Skip to content

Instantly share code, notes, and snippets.

@sonkm3
Created September 8, 2011 01:38
Show Gist options
  • Save sonkm3/1202394 to your computer and use it in GitHub Desktop.
Save sonkm3/1202394 to your computer and use it in GitHub Desktop.
python unicode and string
# -*- 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