|
Simple Sand Samples |
Python > バイナリファイルを読み込む
read-bin.py
import sys,struct
f=open(sys.argv[1])
while 1:
c=f.read(1)
if not c:break
print "%02x" % struct.unpack("B",c),
print
$ echo -ne "\x1\x2\x3" > hoge.bin
$ od -tx1 hoge.bin
0000000 01 02 03
0000003
$ python read-bin.py hoge.bin
01 02 03
$
$ od -tx1 hoge.bin
0000000 01 02 03
0000003
$ python read-bin.py hoge.bin
01 02 03
$