本文整理汇总了Python中ConfigParser.ConfigParser.getfloat方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigParser.getfloat方法的具体用法?Python ConfigParser.getfloat怎么用?Python ConfigParser.getfloat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConfigParser.ConfigParser
的用法示例。
在下文中一共展示了ConfigParser.getfloat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ConfigReader
# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import getfloat [as 别名]
class ConfigReader(object):
"""
为傲世堂的游戏项目配置文件定制的配置读取类。
陈超写的arg.gameOption耦合性太强,只能在bible内使用。
但是配置文件的结构设计的很合理。
此类就是根据原来的结构设计重新写的解耦并且适用性更广的类。
Example::
conf = ConfigReader(game, region)
ip = conf.get("mobile_www_ip")
if conf.has_option("mobile_www_port")
port = conf.getint("mobile_www_port")
"""
def __init__(self, game, section, conf_dir='/app/opbin/work/bible/conf'):
self.game = game
self.section = section
self.conf_file = '{}/{}.conf'.format(conf_dir.rstrip('/'), self.game)
self.config = ConfigParser()
self.config.read(self.conf_file)
self.has_section = self.config.has_section(self.section)
def has_option(self, option):
return self._has_option(self.section, option) or self._has_option('common', option)
def _has_option(self, section, option):
return self.config.has_option(section, option)
def get(self, option, raw=0, var=None):
if self._has_option(self.section, option):
return self.config.get(self.section, option, raw, var)
elif self._has_option('common', option):
return self.config.get('common', option, raw, var)
else:
raise Exception("Can't find option: {} in {}".format(option, self.conf_file))
def getint(self, option):
if self._has_option(self.section, option):
return self.config.getint(self.section, option)
elif self._has_option('common', option):
return self.config.getint('common', option)
else:
raise Exception("Can't find option: {} in {}".format(option, self.conf_file))
def getfloat(self, option):
if self._has_option(self.section, option):
return self.config.getfloat(self.section, option)
elif self._has_option('common', option):
return self.config.getfloat('common', option)
else:
raise Exception("Can't find option: {} in {}".format(option, self.conf_file))
def getboolean(self, option):
if self._has_option(self.section, option):
return self.config.getboolean(self.section, option)
elif self._has_option('common', option):
return self.config.getboolean('common', option)
else:
raise Exception("Can't find option: {} in {}".format(option, self.conf_file))
示例2: read_metadata
# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import getfloat [as 别名]
def read_metadata(filename):
if filename.endswith('bz2'):
fname = os.path.splitext(filename)[0]
else:
fname = filename
if os.path.splitext(fname)[1] == '.cbf':
try:
import pycbf
except ImportError:
raise NeXusError('Reading CBF files requires the pycbf module')
cbf = pycbf.cbf_handle_struct()
cbf.read_file(fname, pycbf.MSG_DIGEST)
cbf.select_datablock(0)
cbf.select_category(0)
cbf.select_column(1)
meta_text = cbf.get_value().splitlines()
date_string = meta_text[2][2:]
time_stamp = epoch(date_string)
exposure = float(meta_text[5].split()[2])
summed_exposures = 1
return time_stamp, exposure, summed_exposures
elif os.path.exists(fname+'.metadata'):
parser = ConfigParser()
parser.read(fname+'.metadata')
return (parser.getfloat('metadata', 'timeStamp'),
parser.getfloat('metadata', 'exposureTime'),
parser.getint('metadata', 'summedExposures'))
else:
return time.time(), 1.0, 1
示例3: read_config
# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import getfloat [as 别名]
def read_config(filename):
"""Read the config file *filename* and replace the values in global
variables.
"""
cfg = ConfigParser()
cfg.read(filename)
station = cfg.get("default", "station")
satellites = cfg.get("default", "satellites").split(",")
forward = cfg.getint("default", "forward")
start = cfg.getfloat("default", "start")
station_name = cfg.get(station, "name")
station_lon = cfg.getfloat(station, "longitude")
station_lat = cfg.getfloat(station, "latitude")
station_alt = cfg.getfloat(station, "altitude")
sat_scores = {}
for sat in satellites:
sat_scores[sat] = (cfg.getfloat(sat, "night"),
cfg.getfloat(sat, "day"))
area = utils.parse_area_file(cfg.get(station, "area_file"),
cfg.get(station, "area"))[0]
return ((station_lon, station_lat, station_alt),
sat_scores, station_name, area, forward, start)
示例4: __init__
# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import getfloat [as 别名]
def __init__(self):
config = ConfigParser()
defaults = getDefaults()
config.read(defaults)
# SAC headers for time window, trace selection, and quality factors
self.twhdrs = config.get("sachdrs", "twhdrs").split()
self.hdrsel = config.get("sachdrs", "hdrsel")
self.qfactors = config.get("sachdrs", "qfactors").split()
self.qheaders = config.get("sachdrs", "qheaders").split()
self.qweights = [float(val) for val in config.get("sachdrs", "qweights").split()]
# SAC plots
self.figsize = [float(val) for val in config.get("sacplot", "figsize").split()]
self.rectseis = [float(val) for val in config.get("sacplot", "rectseis").split()]
self.colorwave = config.get("sacplot", "colorwave")
self.colorwavedel = config.get("sacplot", "colorwavedel")
self.colortwfill = config.get("sacplot", "colortwfill")
self.colortwsele = config.get("sacplot", "colortwsele")
self.alphatwfill = config.getfloat("sacplot", "alphatwfill")
self.alphatwsele = config.getfloat("sacplot", "alphatwsele")
self.npick = config.getint("sacplot", "npick")
self.pickcolors = config.get("sacplot", "pickcolors")
self.pickstyles = config.get("sacplot", "pickstyles").split()
self.minspan = config.getint("sacplot", "minspan")
self.srate = config.getfloat("sacplot", "srate")
self.tapertype = config.get("signal", "tapertype")
self.taperwidth = config.getfloat("signal", "taperwidth")
self.thresholds = [float(val) for val in config.get("sacplot", "thresholds").split()]
self.colorthresholds = config.get("sacplot", "colorthresholds").split()
示例5: __init__
# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import getfloat [as 别名]
def __init__(self):
config = ConfigParser()
defaults = getDefaults()
config.read(defaults)
# SAC headers for time window, trace selection, and quality factors
self.twhdrs = config.get('sachdrs', 'twhdrs').split()
self.hdrsel = config.get('sachdrs', 'hdrsel')
self.qfactors = config.get('sachdrs', 'qfactors').split()
self.qheaders = config.get('sachdrs', 'qheaders').split()
self.qweights = [ float(val) for val in config.get('sachdrs', 'qweights').split() ]
# SAC plots
self.figsize = [ float(val) for val in config.get('sacplot', 'figsize').split() ]
self.rectseis = [ float(val) for val in config.get('sacplot', 'rectseis').split() ]
self.colorwave = config.get('sacplot', 'colorwave')
self.colorwavedel = config.get('sacplot', 'colorwavedel')
self.colortwfill = config.get('sacplot', 'colortwfill')
self.colortwsele = config.get('sacplot', 'colortwsele')
self.alphatwfill = config.getfloat('sacplot', 'alphatwfill')
self.alphatwsele = config.getfloat('sacplot', 'alphatwsele')
self.npick = config.getint('sacplot', 'npick')
self.pickcolors = config.get('sacplot', 'pickcolors')
self.pickstyles = config.get('sacplot', 'pickstyles').split()
self.minspan = config.getint('sacplot', 'minspan')
self.srate = config.getfloat('sacplot', 'srate')
self.tapertype = config.get('signal', 'tapertype')
self.taperwidth = config.getfloat('signal', 'taperwidth')
示例6: setUp
# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import getfloat [as 别名]
def setUp(self):
rid = '60754-10'
config = ConfigParser()
p = '/Users/ross/Sandbox/pychron_validation_data.cfg'
config.read(p)
signals = map(lambda x: map(float, x.split(',')),
[config.get('Signals-{}'.format(rid), k)
for k in ['ar40', 'ar39', 'ar38', 'ar37', 'ar36']])
blanks = map(lambda x: map(float, x.split(',')),
[config.get('Blanks-{}'.format(rid), k)
for k in ['ar40', 'ar39', 'ar38', 'ar37', 'ar36']])
irradinfo = map(lambda x: map(float, x.split(',')),
[config.get('irrad-{}'.format(rid), k) for k in ['k4039', 'k3839', 'ca3937', 'ca3837', 'ca3637', 'cl3638']])
j = config.get('irrad-{}'.format(rid), 'j')
j = map(lambda x: float(x), j.split(','))
baselines = [(0, 0), (0, 0), (0, 0), (0, 0), (0, 0)]
backgrounds = [(0, 0), (0, 0), (0, 0), (0, 0), (0, 0)]
ar37df = config.getfloat('irrad-{}'.format(rid), 'ar37df')
t = math.log(ar37df) / (constants.lambda_37.nominal_value * 365.25)
irradinfo.append(t)
# load results
r = 'results-{}'.format(rid)
self.age = config.getfloat(r, 'age')
self.rad4039 = config.getfloat(r, 'rad4039')
self.ca37k39 = config.getfloat(r, 'ca37k39')
self.age_dict = calculate_arar_age(signals, baselines, blanks, backgrounds, j, irradinfo,
)
示例7: readIni
# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import getfloat [as 别名]
def readIni(nb):
global K, N, cut, gui, distrWE, distrNS, vehphWEA, vehphNSA, maxSumFlow, tlType, intergreenLength, GSum
global phaseMinWE, phaseMaxWE, phaseMinNS, phaseMaxNS, maxGap, detPos
filename = 'input' + str(nb).zfill(2) + '.ini'
ini = ConfigParser()
ini.read(filename)
K = ini.getint("general", "K")
N = ini.getint("general", "N")
cut = ini.getboolean("general", "cut")
gui = ini.getboolean("general", "gui")
distrWE = ini.get("demand", "distrWE")
distrNS = ini.get("demand", "distrNS")
vehphWEA = eval(ini.get("demand", "vehphWEA"))
vehphNSA = eval(ini.get("demand", "vehphNSA"))
maxSumFlow = ini.getint("demand", "maxSumFlow")
tlType = ini.get("TL", "tlType")
intergreenLength = ini.getint("TL", "intergreenLength")
GSum = ini.getfloat("TL", "GSum")
[phaseMinWE, phaseMaxWE] = eval(ini.get("TL", "phaseMinMaxWE"))
[phaseMinNS, phaseMaxNS] = eval(ini.get("TL", "phaseMinMaxNS"))
maxGap = ini.getfloat("TL", "maxGap")
detPos = ini.getfloat("TL", "detPos")
return filename
示例8: compileBlock
# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import getfloat [as 别名]
def compileBlock(configFile, binFile):
config = ConfigParser()
config.read(configFile)
block = (configVersion, )
block += (config.getint("radio", "channel"),)
block += (speeds.index(config.get("radio", "speed").upper()),)
block += (config.getfloat("calib", "pitchTrim"),)
block += (config.getfloat("calib", "rollTrim"),)
bin = struct.pack(structFormat, *block)
#Adding some magic:
bin = "0xBC" + bin
bin += struct.pack("B", 256-checksum256(bin))
#print("Config block checksum: %02x" % bin[len(bin)-1])
bfile = open(binFile, "w")
bfile.write(bin)
bfile.close()
print "Config block compiled successfully to", binFile
示例9: read_header
# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import getfloat [as 别名]
def read_header(folder, n_part, input_):
global config
config = ConfigParser()
config.read(input_)
h_data = []
for j in n_part: # n_part
h_data.append(int(j))
for j in config.get('header', 'mass_array').split(','):
h_data.append(float(j))
h_data.append(config.getfloat('header', 'time'))
h_data.append(config.getfloat('header', 'redshift'))
h_data.append(config.getint('header', 'flag_sfr'))
h_data.append(config.getint('header', 'flag_feedback'))
for j in n_part: # n_part_total, assuming equal to n_part
h_data.append(int(j))
h_data.append(config.getint('header', 'flag_cooling'))
h_data.append(config.getint('header', 'num_files'))
h_data.append(config.getfloat('header', 'boxsize'))
h_data.append(config.getfloat('header', 'omega0'))
h_data.append(config.getfloat('header', 'omega_lambda'))
h_data.append(config.getfloat('header', 'hubble_param'))
h_data.append(config.getint('header', 'flag_age'))
h_data.append(config.getint('header', 'flag_metals'))
# blank, present in the header
for i in np.arange(88):
h_data.append('\0')
s = struct.Struct('iiiiii dddddd d d i i iiiiii i i dddd ii cccc\
cccccccccccccccccccccccccccccccccccccccccccccccccc\
cccccccccccccccccccccccccccccccccc')
packed_data = s.pack(*h_data)
# Need raw h_data as well - D. Rennehan
return packed_data, h_data
示例10: get_ic_factor
# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import getfloat [as 别名]
def get_ic_factor(self, det):
# storing ic_factor in preferences causing issues
# ic_factor stored in detectors.cfg
p = os.path.join(paths.spectrometer_dir, 'detectors.cfg')
# factors=None
ic = 1, 1e-20
if os.path.isfile(p):
c = ConfigParser()
c.read(p)
det = det.lower()
for si in c.sections():
if si.lower() == det:
v, e = 1, 1e-20
if c.has_option(si, 'ic_factor'):
v = c.getfloat(si, 'ic_factor')
if c.has_option(si, 'ic_factor_err'):
e = c.getfloat(si, 'ic_factor_err')
ic = v, e
break
else:
self.debug('no detector file {}. cannot retrieve ic_factor'.format(p))
r = ufloat(*ic)
return r
示例11: test01
# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import getfloat [as 别名]
def test01():
from ConfigParser import ConfigParser
CONFIGFILE='config.txt'
config=ConfigParser()
config.read(CONFIGFILE)
print config.get('messages','greeting')
radius=input(config.get('messages','question')+' ')
print config.get('messages','result_message')
print config.getfloat('numbers','pi')*radius**2
示例12: load_glbv
# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import getfloat [as 别名]
def load_glbv():
"""load global variables from .xls"""
glbv = {}
glbv["path"] = ""
glbv["config_file"] = ""
if platform.system() == "Windows":
glbv["path"] = "D:\Experiment\prefetching-simulation"
glbv["config_file"] = glbv["path"]+"\project\glbv.conf"
elif platform.system() == "Linux":
glbv["path"] = "/home/pzy/test"
glbv["config_file"] = glbv["path"]+"/glbv.conf"
cf = ConfigParser()
cf.read(glbv["config_file"])
glbv["tl"] = cf.getint("glbv", "tl")
glbv["tn"] = cf.getint("glbv", "tn")
glbv["t"] = cf.getint("glbv", "t")
glbv["f"] = cf.getint("glbv", "f")
glbv["n"] = cf.getint("glbv", "n")
glbv["b"] = cf.getint("glbv", "b")
glbv["ot"] = cf.getint("glbv", "ot")
glbv["maxs"] = cf.getint("glbv", "maxs")
glbv["mins"] = cf.getint("glbv", "mins")
glbv["recall"] = cf.getfloat("glbv", "recall")
glbv["precision"] = cf.getfloat("glbv", "precision")
glbv["source"] = cf.get("glbv", "source")
glbv["solver"] = cf.get("glbv", "solver")
glbv["dis"] = cf.get("glbv", "dis")
glbv["wrt"] = cf.get("glbv", "wrt")
glbv["draw"] = cf.get("glbv", "draw")
glbv["data1"] = cf.get("glbv", "data1")
glbv["result1"] = cf.get("glbv", "result1")
glbv["sheet_index"] = cf.getint("glbv", "sheet_index")
glbv["time_col"] = cf.getint("glbv", "time_col")
glbv["size_col"] = cf.getint("glbv", "size_col")
glbv["start_row"] = cf.getint("glbv", "start_row")
glbv["end_row"] = cf.getint("glbv", "end_row")
glbv["t"] = glbv["tn"]*glbv["tl"]
glbv["n"] = glbv["t"]/glbv["f"]
if platform.system() == "Windows":
glbv["data_file"] = glbv["path"]+"\\project\\"+glbv["data1"]
glbv["result_file"] = glbv["path"]+"\\project\\"+glbv["result1"]
elif platform.system() == "Linux":
glbv["data_file"] = glbv["path"]+"/"+glbv["data1"]
glbv["result_file"] = glbv["path"]+"/"+glbv["result1"]
return glbv
示例13: __init__
# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import getfloat [as 别名]
def __init__(self, config_file="body_model.conf", section="BodyModel"):
c = ConfigParser()
if not path.exists(config_file):
print 'Config file %s not found!'%config_file
raise IOError
c.read(config_file)
self.legs = [LegModel() for i in range(NUM_LEGS)]
# Leg Offsets
self.LEG0_OFFSET_X = c.getfloat(section, "leg0_offset_x")
self.LEG0_OFFSET_Y = c.getfloat(section, "leg0_offset_y")
self.LEG0_THETA = c.getfloat(section, "leg0_theta")
self.LEG1_OFFSET_X = c.getfloat(section, "leg1_offset_x")
self.LEG1_OFFSET_Y = c.getfloat(section, "leg1_offset_y")
self.CHASSIS_BOTTOM_Z = c.getfloat(section, "chassis_bottom_z")
示例14: parseConfigurationFile
# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import getfloat [as 别名]
def parseConfigurationFile(self, configFile):
"""
Parse the configuration file to get base model parameters
"""
# Initialize defaults
defaultParams = {}
# CUDA kernels are defined externally in a .cu file
defaultParams["cu_dir"] = os.path.join("pyhawkes", "cuda", "cpp")
defaultParams["cu_file"] = "process_id_kernels.cu"
defaultParams["thin"] = 1
defaultParams["sigma"] = 0.001
defaultParams["kappa"] = 5
defaultParams["nu"] = 4
defaultParams["mu"] = "None"
# Create a config parser object and read in the file
cfgParser = ConfigParser(defaultParams)
cfgParser.read(configFile)
self.params = {}
self.params["cu_dir"] = cfgParser.get("proc_id_model", "cu_dir")
self.params["cu_file"] = cfgParser.get("proc_id_model", "cu_file")
self.params["thin"] = cfgParser.getint("proc_id_model", "thin")
self.params["blockSz"] = cfgParser.getint("cuda", "blockSz")
# Parse the params for the spatial GMM model
self.params["sigma0"] = cfgParser.getfloat("proc_id_model", "sigma")
self.params["kap0"] = cfgParser.getfloat("proc_id_model", "kappa")
self.params["nu0"] = cfgParser.getfloat("proc_id_model", "nu")
# Parse mu0from config file
mu0_str = cfgParser.get("proc_id_model", "mu")
if mu0_str == "None":
# If not specified, take the mean of the data
self.params["mu0"] = np.mean(self.base.data.X, 1)
else:
# Filter out unwanted characters
mu0_str = filter(lambda c: c.isdigit() or c=="," or c=="-" or c==".", mu0_str)
self.params["mu0"] = np.fromstring(mu0_str, sep=",",dtype=np.float32)
self.params["T0"] = self.params["sigma0"]*np.eye(self.base.data.D)
# Parse the desired number of mixture components/processes
self.params["K"] = cfgParser.getint("proc_id_model", "K")
示例15: read
# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import getfloat [as 别名]
def read(self, f):
'''Read the settings from the given file handle.'''
cfg = ConfigParser()
cfg.readfp(f)
netSection = 'Network'
if cfg.has_section(netSection):
if cfg.has_option(netSection, 'defaultIpAddress'):
self.defaultIpAddress = cfg.get(netSection, 'defaultIpAddress')
if cfg.has_option(netSection, 'defaultPort'):
self.defaultPort = cfg.getint(netSection, 'defaultPort')
if cfg.has_option(netSection, 'ephemeralPortsFrom'):
self.ephemeralPorts[0] = cfg.getint(netSection, 'ephemeralPortsFrom')
if cfg.has_option(netSection, 'ephemeralPortsTo'):
self.ephemeralPorts[1] = cfg.getint(netSection, 'ephemeralPortsTo')
tftpSection = 'TFTP'
if cfg.has_section(tftpSection):
if cfg.has_option(tftpSection, 'timeout'):
self.tftpTimeout = cfg.getfloat(tftpSection, 'timeout')
if cfg.has_option(tftpSection, 'retries'):
self.tftpRetries = cfg.getint(tftpSection, 'retries')
serverSection = 'Server'
if cfg.has_section(serverSection):
if cfg.has_option(serverSection, 'defaultDirectory'):
self.defaultDirectory = cfg.get(serverSection, 'defaultDirectory')
if cfg.has_option(serverSection, 'saveLastUsed'):
self.saveLastUsed = cfg.getboolean(serverSection, 'saveLastUsed')