python读取Properties属性文件 发表于 2016-07-19 | 分类于 Python , 编程技术 python 读取 Properties属性文件 12345678910111213141516171819202122class 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