python

pythonで正規表現

import re で。詳細はpydoc re re.compile コンパイルした正規表現オブジェクトを返す re.match 文字列の先頭からマッチさせるときに re.search 文字列のマッチを実行 text = 'hogehoge 100' matchobj = re.search( r"\d+", text) result = matchobj.group()…

python勉強 - 変数を文字列に展開

$ cat foo.py a = 'hoge' b = 'fuga' print 'foobar %s %s' % (a, b) print 'foobar %(a)s %(b)s' % locals() $ python foo.py foobar hoge fuga foobar hoge fuga

pythonのバージョン上がったらyumが使えなくなった

元々python2.4で動いていたらしく、誰かが2.5をソースで入れてから使えなくなった。 # yum There was a problem importing one of the Python modules required to run yum. The error leading to this problem was: No module named yum Please install a p…