2016-07-14 3 views
0

私はいくつかの設定で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)) 

聖霊降臨祭を、しかし、私私は前に言ったようにそれを行うように、それを行う方法は何ですか?任意のヒント?ありがとう

答えて

0

new_value = input(comment+": ")を使用すると、ユーザーから新しい価値を得ることができます。

実際に変数を編集したり、カーソルを移動したりするための高度なコンソールプログラムを作成する場合は、Python標準ライブラリのcursesモジュールを参照してください。

関連する問題