私はいくつかの設定でconfファイルを持っています。私は使いやすいインタフェースを作成するために情報を自動的に解析する必要があります。PythonでConfigParserのlibを使って設定ファイルを操作する
私はコンフィギュレーションでの私のいずれかのセクションの例を与える:
[OutOfHoursAlert]
comment_max_hour = Max Hour
max_hour = 20
comment_min_hour = Min Hour
min_hour = 8
comment_freq = Frequency of Plugin Executation
frequency = 10
目標は、すべてのセクション(これは私は簡単にそれを行う、okです)
ハードパートIドンを読んでいます私の端末インタフェースにコメントを表示し、コメントの下のオプションを変更するオプションです。このような
:
Menu to configure OutOfHoursAlert
Max Hour (read from comment) : (then show the field to edit, in this case max_hour)
Min Hour (read from comment) : (then show the field to edit, in this case min_hour)
FRequency of PLugin Executation (read from comment) : (then show the field to edit, in this case frequency)
私が書くにこの単純なコード持っているすべてのプラグイン読むために: 輸入のConfigParserこれは私がしたいすべてのセクションで辞書を作成
import plugnplay
from plugins.PluginAlert import PluginAlerter
plugnplay.plugin_dirs = ['./plugins']
plugnplay.load_plugins()
plugins = PluginAlerter.implementors()
templist = []
for x in plugins:
temp = str(x).split('.')
templist.append(temp[1])
config = ConfigParser.ConfigParser()
config.readfp(open('./conf.ini'))
for x in templist:
print "\nThe Configurations for plugin "+x+" are:\n"
print dict(config.items(x))
聖霊降臨祭を、しかし、私私は前に言ったようにそれを行うように、それを行う方法は何ですか?任意のヒント?ありがとう