Python edit


This module provides the ConfigParser class which implements a basic configuration language in INI files. You can use this to write Python programs which can be customized by end users easily.



All return values from ConfigParser.ConfigParser().get are strings. It can be converted to more common types thanks to eval

Creating configuration file programmatically

Configuration file contains sections, each section contains keys and values. configparser module can be used to read and write config files. Creating the configuration file:-

import configparser
config = configparser.ConfigParser()
with open('example.ini', 'w') as configfile:

The output file contains below structure

resolution = 320x240
color = blue

If you want to change particular field ,get the field and assign the value


Basic usage

In config.ini:

debug = True
name = Test
password = password

path = /path/to/file

In Python:

from ConfigParser import ConfigParser
config = ConfigParser()

#Load configuration file"config.ini")

# Access the key "debug" in "DEFAULT" section
config.get("DEFAULT", "debug")
# Return 'True'

# Access the key "path" in "FILES" destion
config.get("FILES", "path")
# Return '/path/to/file'

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents
32 Set
46 Enum
105 Stack
119 Mixins
121 ArcPy
127 Arrays
139 Neo4j
141 Curses
146 heapq
155 Audio
156 pyglet
158 ijson
161 Flask
164 pygame
167 Gzip
168 ctypes
171 configparser
187 shelve
  ↑ ↓ to navigate     ↵ to select     Esc to close