37,721
社区成员
发帖
与我相关
我的任务
分享
#!/usr/bin/env python
# coding=utf-8
import ConfigParser
def singleton(cls, *args, **kw):
instances = {}
def _singleton():
if cls not in instances:
instances[cls] = cls(*args, **kw)
return instances[cls]
return _singleton
@singleton
class configs(object):
def __init__(self):
self.ConfigParser = ConfigParser.ConfigParser()
self.ConfigParser.read("config.conf")
def get(self,section,option,types=None):
global result
if section is not None:
sectionall = self.ConfigParser.sections()
for sec in sectionall:
if sec == section:
optionall = self.ConfigParser.options(sec)
if optionall is not None:
for opt in optionall:
if opt == option:
if types == "int":
result = self.ConfigParser.getint(sec,opt)
else:
result = self.ConfigParser.get(sec,opt)
return result