通过以下示例,我可以从[section1]
. 我如何为其他部分或更多部分执行此操作?
store.config
[section1]
field_a = hello
field_b = galaxy
[section2]
field_a = hello
field_b = galaxy
[section3]
field_a = hello
field_b = galaxy
主文件.py
from ConfigParser import SafeConfigParser
class Main:
def get_properties(self, section, *variables):
cfgFile = 'c:\store.config'
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('section1','field_a')
print config_vars
op=Main()
op.run_me()
电流输出:
{'section1': 'field_a'}
这将帮助我改进在Using var from from function A to function B后给出的解决方案。