Code: Alles auswählen
try:
import configparser
except ImportError:
# Python 2.x
import ConfigParser as configparser
[...]
def read_configuration(filename='~/.launchit/launchit.conf'):
filename = os.path.expanduser(filename)
if not os.path.isfile(filename):
return None
with open(filename) as config_file:
# Fake a section to allow "flat" parsing
fake_file = StringIO.StringIO('[dummy]\n' + config_file.read())
parser = configparser.SafeConfigParser()
parser.readfp(fake_file)
return dict(parser.items('dummy'))Code: Alles auswählen
encoding: utf-8
helper: gnome-openCode: Alles auswählen
In [1]: import core
In [2]: core.read_configuration()
Out[2]: {'encoding': 'utf-8', 'helper': 'gnome-open'}