Tue, October 10, 2006
{update:2007-01-15}
Jythonでよく使うテクニック(2) ファイルの拡張子だけ変更したい
{strong:foo.txt} を処理して、 結果を{strong:foo.html}というファイル名にして保存したい、 ということがあります。
reモジュール
そんなときは、 reモジュールを使って置き換えします。
import re
file="foo.txt"
matchstr=re.compile("\.txt$")
htmlf=matchstr.sub(".html",file)
print htmlf
ちなみに、bashでこれをやるには、以下のページを参照のこと。