トップ 差分 一覧 ソース 検索 ヘルプ RSS ログイン

BugTrack-その他のメモ/34

R備忘録 /状態空間モデリング/donlp2/その他のメモ

エンコードされて16進数になっている文字列をデコードする

  • 投稿者: みゅ
  • カテゴリ: Python
  • 優先度: 普通
  • 状態: 完了
  • 日時: 2010年07月21日 10時56分11秒

内容

  • メモ
hexStr = re.compile('\\\\x(..?)|([0-9A-Za-z^`_\[\]\|{}@~!"#\$%&\'=\-]|\\\\?)')
def _trans(self, txt, charset='sjis'):
	aa = hexStr.findall(txt)
	aaa = ''
	for m in aa:
		if m[1] != '':
			aaa = aaa + m[0] + re.sub('0x','',hex(ord(m[1])))
		else:
			aaa = aaa + m[0]
	bbb = aaa.decode("hex").decode(charset)
	return urllib.unquote_plus(bbb)

コメント