-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_parser.py
More file actions
34 lines (26 loc) · 818 Bytes
/
config_parser.py
File metadata and controls
34 lines (26 loc) · 818 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
import ConfigParser
import itertools
import os
def config_write():
config = ConfigParser.RawConfigParser()
config.add_section('Section1')
config.set('Section1', 'an_int', 12)
with open('example2.cfg', 'wb') as configfile:
config.write(configfile)
config.read('example.cfg')
def config_read():
config = ConfigParser.RawConfigParser()
if os.path.exists("example2.cfg"):
config.read('example2.cfg')
an_int = config.getint("Section1", "an_int")
"""
try:
an_int = config.getint("Section2", "an_int")
except ConfigParser.NoSectionError:
print "No such section exists..."
pass
"""
params = {"an_int" : an_int }
print params["an_int"]
config_write()
config_read()