以下に説明するコードを使用すると、file.cfgに格納されているプロパティを正常に取得できますが、出力を他の変数に使用するにはどうすればよいですか?
from ConfigParser import SafeConfigParser
class Main:
def get_properties(self, section, *variables):
cfgFile = 'c:\file.cfg'
parser = SafeConfigParser()
parser.read(cfgFile)
properties= variables
return {
variable : parser.get(section,variable) for variable in properties
}
def run_me(self):
config_vars= self.get_properties('database','host','dbname')
print config_vars
op=Main()
op.run_me()
私はまだPythonを学んでいますが、出力を個々の変数に設定するために何をする必要があるのかわかりません。
現在の出力:
{'host': 'localhost', 'dbname': 'sample'}
私が欲しいもの:
db_host = localhost
db_name = sample