forked from arvimal/100DaysofCode-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02-configparser-2.py
More file actions
30 lines (23 loc) · 839 Bytes
/
02-configparser-2.py
File metadata and controls
30 lines (23 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python3
import configparser
# Defining the configuration file
path = "config_file_1.conf"
# Creating the `config` object from `configparse`
config = configparser.ConfigParser()
# Reading from the configuration file
config.read(path)
# Read a couple of existing configurations,
# under the `Settings` section.
font = config.get("Settings", "font")
font_size = config.get("Settings", "font_size")
# Change/Set a couple of configurations under the
# `Settings` section. The same syntax is also used
# to create new ones.
config.set("Settings", "font_size", "15")
config.set("Settings", "font", "monaco")
# Remove a configuration under `Settings`
config.remove_option("Settings", "font_style")
# Open the configuration file, and write the
# new changes.
with open(path, "w") as config_file:
config.write(config_file)