Skip to content

Commit 6eaa175

Browse files
Irina NicolaeIrina Nicolae
authored andcommitted
Correct config init for python2
1 parent e40cba4 commit 6eaa175

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

config/__init__.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@
1010
import ConfigParser as cp
1111

1212

13+
def config_to_dict(section):
14+
dict = {}
15+
options = parser.options(section)
16+
for option in options:
17+
try:
18+
dict[option] = parser.get(section, option)
19+
except:
20+
print("exception on %s!" % option)
21+
dict[option] = None
22+
return dict
23+
24+
1325
__all__ = ['config_dict', 'MNIST_PATH', 'CIFAR10_PATH', 'IMAGENET_PATH', 'STL10_PATH', 'DATA_PATH']
1426

1527
config_file = join(dirname(__file__), 'config.ini')
@@ -22,13 +34,19 @@
2234

2335
# Generate config dictionary
2436
config_dict = dict()
25-
config_dict.update(parser['DEFAULT'])
37+
if sys.version_info >= (3, 0):
38+
config_dict.update(parser['DEFAULT'])
39+
else:
40+
config_dict['profile'] = parser.get('DEFAULT', 'profile')
2641

27-
profile = config_dict['profile'] = config_dict.get('profile', 'profile1')
42+
profile = config_dict['profile'] = config_dict.get('profile')
2843

2944
# Load the configuration for the current profile
3045
if parser.has_section(profile):
31-
config_dict.update(parser[profile])
46+
if sys.version_info >= (3, 0):
47+
config_dict.update(parser[profile])
48+
else:
49+
config_dict.update(config_to_dict(profile))
3250

3351
# Add configured paths to PYTHONPATH
3452
for key in config_dict:

0 commit comments

Comments
 (0)