本文整理匯總了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()