June 2025
Beginner to intermediate
473 pages
13h 30m
English
INI files are text files for storing key-value pairs. An INI file can be divided into various sections by using [section]:
; File config.ini[server]hostname = example.comport = 8080[data]imagePath = /mnt/imagesdbName = mydb
INI files are often used to store configuration data. Only semicolons are provided for marking comments. Especially in the Linux environment, however, # is also mostly accepted.
The easiest way to read INI files in Python is to use the ConfigParser module. The following listing shows the intuitive application. Note that the parser always returns strings. If you want to use port number 8080 as a number, you must perform an appropriate conversion using int().
# Sample file read-config.py ...
Read now
Unlock full access