python读取Properties属性文件

python 读取 Properties属性文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Properties:
file_name = ''
def __init__(self, file_name):
self.file_name = file_name
def get_properties(self):
try:
pro_file = open(self.file_name, 'r')
properties = {}
for line in pro_file:
if line.find('#') >= 0:
continue
if line.find('=') > 0:
strs = line.replace('\n', '').split('=')
properties[strs[0]] = strs[1]
except Exception, e:
raise e
else:
pro_file.close()
return properties