Pythonでのバイナリデータの扱い
バイナリデータの定義
print "\xff" # 16進の0xff文字列
16進数を文字列に変換
from binascii import * x = "\xff" s = b2a_hex(x) print "%r"%s
文字列を16進に変換
from binascii import * s = "ffffff" x = a2b_hex(s) print "%r"%x for c in x: print "%r"%c
print "\xff" # 16進の0xff文字列
from binascii import * x = "\xff" s = b2a_hex(x) print "%r"%s
from binascii import * s = "ffffff" x = a2b_hex(s) print "%r"%x for c in x: print "%r"%c