0
當我在Linux中使用python解析它時,如何將輸入作爲逗號分隔值輸入ini
文件中。ini配置文件中的逗號分隔值
下面你會發現MWE
#!/usr/bin/env python
import configparser
def parse_config(file):
global config_dictionary
config_dictionary={}
config=configparser.ConfigParser()
config.read(file)
for section in config.sections():
config_dictionary[section] = {}
for option in config.options(section):
config_dictionary[section][option] = config.get(section, option)
return config_dictionary
def main():
config_path = 'test.ini'
config_dict=parse_config(config_path)
mapping = config_dict['Options']['initialassignment']
mapping = list(mapping)
print mapping
if __name__ == "__main__":
main()
和test.ini
文件
[Options]
initialAssignment=0,1,2,3