Using the code described bellow, i can sucessfully retrieve the properties stored into the file.cfg, but how can i use the output into others variables?
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()
Im still learning Python, but i’m not sure what i need to do to set the output into individual variables:
current output:
{'host': 'localhost', 'dbname': 'sample'}
what i would like to have:
db_host = localhost
db_name = sample
You recieved dict-object
config_vars, so your can using config variables as values of the dict:Read more about python dictionaries in documentation.