本文整理汇总了Python中attrdict.AttrDict.pop方法的典型用法代码示例。如果您正苦于以下问题:Python AttrDict.pop方法的具体用法?Python AttrDict.pop怎么用?Python AttrDict.pop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类attrdict.AttrDict
的用法示例。
在下文中一共展示了AttrDict.pop方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_pop_removes_item
# 需要导入模块: from attrdict import AttrDict [as 别名]
# 或者: from attrdict.AttrDict import pop [as 别名]
def test_pop_removes_item():
d = AttrDict(k=True)
try:
d['k']
except KeyError:
assert False, "KeyError shouldn't be raised yet"
d.pop('k')
d['k']
示例2: test_pop_removes_attr
# 需要导入模块: from attrdict import AttrDict [as 别名]
# 或者: from attrdict.AttrDict import pop [as 别名]
def test_pop_removes_attr():
d = AttrDict(k=True)
try:
d.k
except AttributeError:
assert False, "AttributeError shouldn't be raised yet"
d.pop('k')
d.k
示例3: Process
# 需要导入模块: from attrdict import AttrDict [as 别名]
# 或者: from attrdict.AttrDict import pop [as 别名]
#.........这里部分代码省略.........
Remove albedo subprocess from energy balance model::
>>> import climlab
>>> model = climlab.EBM()
>>> print model
climlab Process of type <class 'climlab.model.ebm.EBM'>.
State variables and domain shapes:
Ts: (90, 1)
The subprocess tree:
top: <class 'climlab.model.ebm.EBM'>
diffusion: <class 'climlab.dynamics.diffusion.MeridionalDiffusion'>
LW: <class 'climlab.radiation.AplusBT.AplusBT'>
albedo: <class 'climlab.surface.albedo.StepFunctionAlbedo'>
iceline: <class 'climlab.surface.albedo.Iceline'>
cold_albedo: <class 'climlab.surface.albedo.ConstantAlbedo'>
warm_albedo: <class 'climlab.surface.albedo.P2Albedo'>
insolation: <class 'climlab.radiation.insolation.P2Insolation'>
>>> model.remove_subprocess('albedo')
>>> print model
climlab Process of type <class 'climlab.model.ebm.EBM'>.
State variables and domain shapes:
Ts: (90, 1)
The subprocess tree:
top: <class 'climlab.model.ebm.EBM'>
diffusion: <class 'climlab.dynamics.diffusion.MeridionalDiffusion'>
LW: <class 'climlab.radiation.AplusBT.AplusBT'>
insolation: <class 'climlab.radiation.insolation.P2Insolation'>
"""
try:
self.subprocess.pop(name)
except KeyError:
if verbose:
print('WARNING: {} not found in subprocess dictionary.'.format(name))
self.has_process_type_list = False
def set_state(self, name, value):
"""Sets the variable ``name`` to a new state ``value``.
:param string name: name of the state
:param value: state variable
:type value: :class:`~climlab.domain.field.Field` or *array*
:raises: :exc:`ValueError`
if state variable ``value`` is not having a domain.
:raises: :exc:`ValueError`
if shape mismatch between existing domain and
new state variable.
:Example:
Resetting the surface temperature of an EBM to
:math:`-5 ^{\circ} \\textrm{C}` on all latitues::
>>> import climlab
>>> from climlab import Field
>>> import numpy as np
>>> # setup model
>>> model = climlab.EBM(num_lat=36)
>>> # create new temperature distribution
>>> initial = -5 * ones(size(model.lat))
>>> model.set_state('Ts', Field(initial, domain=model.domains['Ts']))
示例4: KBConfig
# 需要导入模块: from attrdict import AttrDict [as 别名]
# 或者: from attrdict.AttrDict import pop [as 别名]
class KBConfig(object):
def __init__(self):
# The default configuration file for KloudBuster
default_cfg = resource_string(__name__, "cfg.scale.yaml")
# Read the configuration file
self.config_scale = AttrDict(yaml.safe_load(default_cfg))
self.alt_cfg = None
self.cred_tested = None
self.cred_testing = None
self.server_cfg = None
self.client_cfg = None
self.topo_cfg = None
self.tenants_list = None
self.storage_mode = False
self.multicast_mode = False
def update_configs(self):
# Initialize the key pair name
if self.config_scale['public_key_file']:
# verify the public key file exists
if not os.path.exists(self.config_scale['public_key_file']):
LOG.error('Error: Invalid public key file: ' + self.config_scale['public_key_file'])
sys.exit(1)
else:
# pick the user's public key if there is one
pub_key = os.path.expanduser('~/.ssh/id_rsa.pub')
if os.path.isfile(pub_key):
self.config_scale['public_key_file'] = pub_key
LOG.info('Using %s as public key for all VMs' % (pub_key))
else:
LOG.warning('No public key is found or specified to instantiate VMs. '
'You will not be able to access the VMs spawned by KloudBuster.')
if self.storage_mode:
disk_size = self.config_scale.client.storage_stage_configs.disk_size
io_file_size = self.config_scale.client.storage_stage_configs.io_file_size
if not disk_size:
LOG.error('You have to specify a disk size in order to run storage tests.')
raise KBConfigParseException()
if io_file_size > disk_size:
LOG.error('io_file_size must be less or eqaul than disk_size.')
raise KBConfigParseException()
if self.alt_cfg:
self.config_scale = self.config_scale + AttrDict(self.alt_cfg)
# Use the default image name for Glance
# defaults to something like "kloudbuster_v3"
if not self.config_scale['image_name']:
self.config_scale['image_name'] = kb_vm_agent.get_image_name()
# A bit of config dict surgery, extract out the client and server side
# and transplant the remaining (common part) into the client and server dict
self.server_cfg = AttrDict(self.config_scale.pop('server'))
self.client_cfg = AttrDict(self.config_scale.pop('client'))
self.server_cfg.update(self.config_scale)
self.client_cfg.update(self.config_scale)
# Hardcode a few client side options
self.client_cfg.update(hardcoded_client_cfg)
# Adjust the VMs per network on the client side to match the total
# VMs on the server side (1:1)
# There is an additional VM in client kloud as a proxy node
if self.storage_mode:
self.client_cfg['vms_per_network'] = \
self.client_cfg.storage_stage_configs.vm_count + 1
else:
self.client_cfg['vms_per_network'] = \
self.get_total_vm_count(self.server_cfg) + 1
# If multicast mode, the number of receivers is specified in the multicast config instead.
if self.multicast_mode:
self.server_cfg['vms_per_network'] =\
self.client_cfg['multicast_tool_configs']['receivers'][-1]
self.config_scale['server'] = self.server_cfg
self.config_scale['client'] = self.client_cfg
# missing rate or rate_iops = 0 = no-limit
# note we need to use key based access to modify the content
# (self.config_scale['client'].storage_tool_configs will make a shallow copy)
for tc in self.config_scale['client']['storage_tool_configs']:
if 'rate' not in tc:
tc['rate'] = '0'
if 'rate_iops' not in tc:
tc['rate_iops'] = 0
def init_with_cli(self):
self.storage_mode = CONF.storage
self.multicast_mode = CONF.multicast
self.get_credentials()
self.get_configs()
self.get_topo_cfg()
self.get_tenants_list()
self.update_configs()
def init_with_rest_api(self, **kwargs):
#.........这里部分代码省略.........