2008年12月20日土曜日

pythonのお勉強【ConfigParser】

設定ファイル操作モジュール

#!/usr/bin/env python
#-*- coding:utf-8 -*-
import ConfigParser


COFIG_FILE='setup.ini'

#- 設定ファイルの読み込み
conf=ConfigParser.SafeConfigParsre()
conf.read( CONFIG_FILE )

#セクションの取得
conf.sections()

#指定セクションの中のオプションの取得
conf.options(conf.sections()[0])

#セクションの追加
conf.add_section( 'sample')

#セクションの削除
conf.remove_section( 'options' )


# オプション、値の設定
conf.set('sample','hoge','fuga')

#設定ファイルの出力
fp_out = open( 'setup2.ini','w')
conf.write( fp_out)


http://www.python.jp/doc/2.4/lib/RawConfigParser-objects.html