-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp_configparser.py
More file actions
36 lines (27 loc) · 805 Bytes
/
p_configparser.py
File metadata and controls
36 lines (27 loc) · 805 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
import configparser
config = configparser.ConfigParser()
config.read('text.ini', encoding='utf-8')
ret = config.sections()
print(ret)
ret = config.items('section1')
print(ret)
ret = config.options('section1')
print(ret)
v = config.get('section1', 'k1')
# v = config.getint('section1', 'k1')
# v = config.getfloat('section1', 'k1')
# v = config.getboolean('section1', 'k1')
print(v)
has_sec = config.has_section('section3')
print(has_sec)
# config.add_section('section3')
# config.write(open('text.ini', 'w'))
#
# config.remove_section('section3')
# config.write(open('text.ini', 'w'))
has_opt = config.has_option('section1', 'k1')
print(has_opt)
# config.remove_option('section', 'k1')
# config.write(open('text.ini', 'w'))
config.set('section1', 'k1', '123')
config.write(open('text.ini', 'w'))