简体   繁体   中英

How to read muliple values from a config file using config parser

I have made a Config file and have multiple values for a keyword as:

[section]

database: mysql , sqlite

and i want to access the values separately..How to go about it??

How about using standard ConfigParser and not using comma?

[section]

database: mysql sqlite

When you get the variable, just split it:

databases = configparser.get('database').split()

Using space for separating options has the disadvantage that if space is already present in the options, as in the case of file names, it wont work. So better to use comma and split using .split(',') and remove leading/trailing whitespaces.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM