-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_configparser.py
More file actions
38 lines (25 loc) · 827 Bytes
/
_configparser.py
File metadata and controls
38 lines (25 loc) · 827 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
31
32
33
34
35
36
37
38
import configparser
PATH = '' # *.ini file
SECTION = ''
OPTION = ''
print('PATH: ', PATH)
print('SECTION: ', SECTION)
print('OPTION: ', OPTION)
config = configparser.ConfigParser()
config.read(PATH)
# list of available sections
print('Sections: ', list(config.keys()))
# check the existence of elements
print('has section: ', config.has_section(SECTION))
print('has option: ', config.has_option(SECTION, OPTION))
# print whole values
for section in config.keys():
print()
print(f' {section} '.center(20, '-'))
for item in config[section]:
print(f"{item} = <{config.get(section, item)}>")
print()
# get a certain element
item = config[SECTION][OPTION]
item = config.get(SECTION, OPTION)
item = config.getint(SECTION, OPTION) # .getboolean() | .getfloat()