本文整理汇总了Python中configparser.ConfigParser.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigParser.__init__方法的具体用法?Python ConfigParser.__init__怎么用?Python ConfigParser.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类configparser.ConfigParser
的用法示例。
在下文中一共展示了ConfigParser.__init__方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from configparser import ConfigParser [as 别名]
# 或者: from configparser.ConfigParser import __init__ [as 别名]
def __init__(self, config_file):
# config = ConfigParser()
super().__init__()
self.test = None
self.train = None
config = myconf()
config.read(config_file)
self._config = config
self.config_file = config_file
print('Loaded config file sucessfully.')
for section in config.sections():
for k, v in config.items(section):
print(k, ":", v)
if not os.path.isdir(self.save_direction):
os.mkdir(self.save_direction)
config.write(open(config_file, 'w'))
示例2: __init__
# 需要导入模块: from configparser import ConfigParser [as 别名]
# 或者: from configparser.ConfigParser import __init__ [as 别名]
def __init__(self, config_file):
# config = ConfigParser()
super().__init__()
self.test = None
self.train = None
config = myconf()
config.read(config_file)
# if config.has_section(self.add_sec) is False:
# config.add_section(self.add_sec)
self._config = config
self.config_file = config_file
print('Loaded config file Successfully.')
for section in config.sections():
for k, v in config.items(section):
print(k, ":", v)
if not os.path.isdir(self.save_direction):
os.mkdir(self.save_direction)
config.write(open(config_file, 'w'))
示例3: __init__
# 需要导入模块: from configparser import ConfigParser [as 别名]
# 或者: from configparser.ConfigParser import __init__ [as 别名]
def __init__(self, config_files):
Parser.__init__(self)
# Write options in the case it was read.
# self.optionxform = str
# Parse to real path
self.config_files = []
for config_file in config_files:
self.config_files.append(os.path.realpath(config_file))
self.config_location = os.path.dirname(os.path.realpath(config_file))
# Parse all config files in list
for config_file in self.config_files:
if os.path.isfile(config_file):
logging.info("Using config file " + config_file)
if PY2:
self.readfp(open(config_file))
else:
self.read_file(open(config_file))
else:
logging.warning("Missing config file " + config_file)
# Might also add command line options for overriding stuff
示例4: __init__
# 需要导入模块: from configparser import ConfigParser [as 别名]
# 或者: from configparser.ConfigParser import __init__ [as 别名]
def __init__(self, config_file):
# config = ConfigParser()
super().__init__()
self.test = None
self.train = None
config = myconf()
config.read(config_file)
# if config.has_section(self.add_sec) is False:
# config.add_section(self.add_sec)
self._config = config
self.config_file = config_file
print('Loaded config file sucessfully.')
for section in config.sections():
for k, v in config.items(section):
print(k, ":", v)
if not os.path.isdir(self.save_direction):
os.makedirs(self.save_direction)
config.write(open(config_file, 'w'))
示例5: __init__
# 需要导入模块: from configparser import ConfigParser [as 别名]
# 或者: from configparser.ConfigParser import __init__ [as 别名]
def __init__(self, path, *args, **kwargs):
ConfigParser.__init__(self, *args, **kwargs)
if os.path.exists(path):
with open(path) as fh:
click.echo("Parsing: %s" % fh.name)
self.readfp(fh)
if os.path.exists(path + ".d"):
for filename in os.listdir(path + ".d"):
if not filename.endswith(".conf"):
continue
with open(os.path.join(path + ".d", filename)) as fh:
click.echo("Parsing: %s" % fh.name)
self.readfp(fh)
示例6: __init__
# 需要导入模块: from configparser import ConfigParser [as 别名]
# 或者: from configparser.ConfigParser import __init__ [as 别名]
def __init__(self, config_file):
if sys.version[0] == "2":
CP.__init__(self)
else:
super().__init__()
if not os.path.exists(config_file):
raise Exception("Could not find " + config_file)
f = open(config_file)
id_string = f.readline().split("=")
if id_string[0].strip().upper() in ["CAPI", "SAPI"]:
self.type = id_string[0]
else:
raise SyntaxError("Could not find API type in " + config_file)
try:
self.version = int(id_string[1].strip())
except ValueError:
raise SyntaxError("Unknown version '{}'".format(id_string[1].strip()))
except IndexError:
raise SyntaxError("Could not find API version in " + config_file)
if sys.version[0] == "2":
exceptions = (configparser.ParsingError, configparser.DuplicateSectionError)
else:
exceptions = (
configparser.ParsingError,
configparser.DuplicateSectionError,
configparser.DuplicateOptionError,
)
try:
if sys.version[0] == "2":
self.readfp(f)
else:
self.read_file(f)
except configparser.MissingSectionHeaderError:
raise SyntaxError("Missing section header")
except exceptions as e:
raise SyntaxError(e.message)
示例7: __init__
# 需要导入模块: from configparser import ConfigParser [as 别名]
# 或者: from configparser.ConfigParser import __init__ [as 别名]
def __init__(self, localAddr, localPort, workers):
self.localAddr = localAddr or ''
self.localPort = int(localPort)
self.workers = workers
示例8: __init__
# 需要导入模块: from configparser import ConfigParser [as 别名]
# 或者: from configparser.ConfigParser import __init__ [as 别名]
def __init__(self, keyring_name='ofxclient',
keyring_available=KEYRING_AVAILABLE, **kwargs):
if sys.version_info >= (3,):
# python 3
ConfigParser.__init__(self, interpolation=None)
else:
# python 2
ConfigParser.__init__(self)
self.keyring_name = keyring_name
self.keyring_available = keyring_available
self._unsaved = {}
self.keyring_name = keyring_name
示例9: __init__
# 需要导入模块: from configparser import ConfigParser [as 别名]
# 或者: from configparser.ConfigParser import __init__ [as 别名]
def __init__(self, filename, *args, **kw):
ConfigParser.__init__(self, *args, **kw)
self.filename = filename
if hasattr(self, '_interpolation'):
self._interpolation = self.InterpolateWrapper(self._interpolation)
示例10: __init__
# 需要导入模块: from configparser import ConfigParser [as 别名]
# 或者: from configparser.ConfigParser import __init__ [as 别名]
def __init__(self):
ConfigParser.__init__(self)
示例11: __init__
# 需要导入模块: from configparser import ConfigParser [as 别名]
# 或者: from configparser.ConfigParser import __init__ [as 别名]
def __init__(self, defaults=None):
ConfigParser.__init__(self, defaults=defaults)
示例12: __init__
# 需要导入模块: from configparser import ConfigParser [as 别名]
# 或者: from configparser.ConfigParser import __init__ [as 别名]
def __init__(self, cfgFile, cfgDefaults=None):
"""
cfgFile - string, fully specified configuration file name
"""
self.file = cfgFile
ConfigParser.__init__(self, defaults=cfgDefaults, strict=False)
示例13: __init__
# 需要导入模块: from configparser import ConfigParser [as 别名]
# 或者: from configparser.ConfigParser import __init__ [as 别名]
def __init__(self, default_config, *args, **kwargs):
ConfigParser.__init__(self, *args, **kwargs)
if default_config is not None:
self.read_string(default_config)
示例14: __init__
# 需要导入模块: from configparser import ConfigParser [as 别名]
# 或者: from configparser.ConfigParser import __init__ [as 别名]
def __init__(self, path):
ConfigParser.__init__(self)
self.read(path)
self.data = self._asDict()