Skip to content

Instantly share code, notes, and snippets.

@NoahTheDuke
Created April 3, 2018 15:17
Show Gist options
  • Save NoahTheDuke/e6d282b421f6a126062e81696e4cfc2a to your computer and use it in GitHub Desktop.
Save NoahTheDuke/e6d282b421f6a126062e81696e4cfc2a to your computer and use it in GitHub Desktop.
Custom configparser wrapper
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