Module Name : LoadCfg
Parameters : Input File
Output : Dictionary Variable with all
the configuration values in organised way
Configuration File Format
-----------------------------------
config.ini
PARAM1 = VALUE1
PARAM2 = VALUE2
.
.
.
Example:
Cricket_config.ini
Captain = Dhoni
Vice Captain = Shewag
Coach = Gary Kristen
Team = India
teamInfo =
LoadCfg("Cricket_config.ini")
teamInfo["Captain"] will Give
Dhoni
teamInfo["Team"] will Give
India
def LoadCfg(filename): result=[] fileptr = open(filename,"r") for line in fileptr: spt_str=line.split("=") spt_str[0]= spt_str[0].strip() spt_str[1]= spt_str[1].strip('\n') spt_str[1]= spt_str[1].strip() spt_str[1]= spt_str[1].strip('"') result.append(spt_str) fileptr.close() return dict(result)
Great blog post. Loved it absolutely. python training in Chennai