PYTHON

  minte9
REMEMBERS




Ini

Ini file are writed with no quotes.
 
[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'
assert M9_URLs[1].strip() == 'https://www.minte9.com/java'
assert DEBUG == 'False'

Questions     github Strings
Escape
        A B C D E F
🔔
1/1