minte9
LearnRemember



Files .ini

Ini file are writted with no quotes.
 
#config.ini

[HOME]
UNIX = /home/catalin
WINDOWS = c:/Users/catalin

[M9]
URLS =
    https://www.minte9.com/python,
    https://www.minte9.com/java,
    https://www.minte9.com/php,
    https://www.minte9.com/javascript

[APP]
DEBUG = False
    # False is string, not boolean

Parser

Config files are parsed much like dictionaries.
 
"""Read config.ini file:
"""
import configparser, pathlib
DIR = pathlib.Path(__file__).resolve().parent

config = configparser.ConfigParser()
config.read(DIR/'config.ini')

HOME_UNIX = config['HOME']['UNIX']
HOME_WINDOWS = config['HOME']['WINDOWS']
M9_URLs = config['M9']['URLS'].split(',')
DEBUG = config['APP']['DEBUG']

assert HOME_UNIX == '/home/catalin'                         # pass
assert DEBUG == 'False'                                     # pass
assert M9_URLs[1].strip() == 'https://www.minte9.com/java'  # pass



  Last update: 420 days ago