Created
April 3, 2018 15:17
-
-
Save NoahTheDuke/e6d282b421f6a126062e81696e4cfc2a to your computer and use it in GitHub Desktop.
Custom configparser wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import configparser | |
import itertools as it | |
import re | |
_config = configparser.ConfigParser(interpolation=configparser.ExtendedInterpolation()) | |
_config.read('config.ini') | |
# expose built-in methods | |
get = _config.get | |
getboolean = _config.getboolean | |
getfloat = _config.getfloat | |
getint = _config.getint | |
def getlist(section, option): | |
lines = get(section, option).splitlines() | |
return filter(None, it.chain.from_iterable(map(lambda x: re.split('[ ,\[\]]', x), lines))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment