2006-01-11から1日間の記事一覧

Pythonのちょっとしたテクニック集

比較演算子をつなげて使う timer = 0 while True: print "%d:"%timer, if 0 <= timer < 1: print "Init" elif 1 <= timer < 10: print "MainLoop" else: print "Finish" break timer += 1 enumerateでインデックスと値を同時に取る arr = ["hoge", "piyo", "…

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 "%…