本文整理汇总了Python中six.itervalues方法的典型用法代码示例。如果您正苦于以下问题:Python six.itervalues方法的具体用法?Python six.itervalues怎么用?Python six.itervalues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类six
的用法示例。
在下文中一共展示了six.itervalues方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: imspec_lookup
# 需要导入模块: import six [as 别名]
# 或者: from six import itervalues [as 别名]
def imspec_lookup(imspec, k, default=None):
'''
imspec_lookup(imspec, k) yields the value associated with the key k in the mapping imspec; if k
is not in imspec, then imspec alises are checked and the appropriate value is returned;
otherwise None is returned.
imspec_lookup(imspec, k, default) yields default if neither k not an alias cannot be found.
'''
k = k.lower()
if k in imspec: return imspec[k]
aliases = imspec_aliases.get(k, None)
if aliases is None:
for q in six.itervalues(imspec_aliases):
if k in q:
aliases = q
break
if aliases is None: return default
for kk in aliases:
if kk in imspec: return imspec[kk]
return default
示例2: delete_templates
# 需要导入模块: import six [as 别名]
# 或者: from six import itervalues [as 别名]
def delete_templates(self, *templates):
'''
Delete templates and related windows
Parameters
----------
templates : one-or-more strings or Template objects
The template to delete
'''
for item in templates:
template_key = getattr(item, 'name', item)
template = self.templates[template_key]
self.delete_windows(*six.itervalues(template.windows))
del self.templates[template_key]
return self.templates
示例3: _check_delete
# 需要导入模块: import six [as 别名]
# 或者: from six import itervalues [as 别名]
def _check_delete(self):
'''Check project delete'''
now = time.time()
for project in list(itervalues(self.projects)):
if project.db_status != 'STOP':
continue
if now - project.updatetime < self.DELETE_TIME:
continue
if 'delete' not in self.projectdb.split_group(project.group):
continue
logger.warning("deleting project: %s!", project.name)
del self.projects[project.name]
self.taskdb.drop(project.name)
self.projectdb.drop(project.name)
if self.resultdb:
self.resultdb.drop(project.name)
for each in self._cnt.values():
del each[project.name]
示例4: __init__
# 需要导入模块: import six [as 别名]
# 或者: from six import itervalues [as 别名]
def __init__(self, models, optimizer, stage_manager, device=None, **kwargs):
if len(models) == 3:
models = models + [None, None]
self.map, self.gen, self.dis, self.smoothed_gen, self.smoothed_map = models
assert isinstance(optimizer, dict)
self._optimizers = optimizer
if device is not None and device >= 0:
for _optimizer in six.itervalues(self._optimizers):
_optimizer.target.to_gpu(device)
self.device = device
# Stage manager
self.stage_manager = stage_manager
# Parse kwargs for updater
self.use_cleargrads = kwargs.pop('use_cleargrads')
self.smoothing = kwargs.pop('smoothing')
self.lambda_gp = kwargs.pop('lambda_gp')
self.total_gpu = kwargs.pop('total_gpu')
self.style_mixing_rate = kwargs.pop('style_mixing_rate')
示例5: leave_module
# 需要导入模块: import six [as 别名]
# 或者: from six import itervalues [as 别名]
def leave_module(self, node): # pylint: disable=unused-argument
for all_groups in six.itervalues(self._bad_names):
if len(all_groups) < 2:
continue
groups = collections.defaultdict(list)
min_warnings = sys.maxsize
for group in six.itervalues(all_groups):
groups[len(group)].append(group)
min_warnings = min(len(group), min_warnings)
if len(groups[min_warnings]) > 1:
by_line = sorted(groups[min_warnings],
key=lambda group: min(warning[0].lineno for warning in group))
warnings = itertools.chain(*by_line[1:])
else:
warnings = groups[min_warnings][0]
for args in warnings:
self._raise_name_warning(*args)
示例6: set
# 需要导入模块: import six [as 别名]
# 或者: from six import itervalues [as 别名]
def set(self, *args, **kwargs):
for k, v in six.iteritems(kwargs):
_set = False
for deps in six.itervalues(self._dependencies):
# try to set args
for arg in deps[0]:
if arg._name_no_id() == k:
arg._dirty = (arg._value != v)
arg._value = v
_set = True
break
if _set:
continue
# try to set kwargs
for kwarg in six.itervalues(deps[1]):
if kwarg._name_no_id() == k:
kwarg._dirty = (kwarg._value != v)
kwarg._value = v
_set = True
break
示例7: _get_active_route_destinations
# 需要导入模块: import six [as 别名]
# 或者: from six import itervalues [as 别名]
def _get_active_route_destinations(context, route_table):
vpn_connections = {vpn['vpn_gateway_id']: vpn
for vpn in db_api.get_items(context, 'vpn')}
dst_ids = [route[id_key]
for route in route_table['routes']
for id_key in ('gateway_id', 'network_interface_id')
if route.get(id_key) is not None]
dst_ids.extend(route_table.get('propagating_gateways', []))
destinations = {item['id']: item
for item in db_api.get_items_by_ids(context, dst_ids)
if (item['vpc_id'] == route_table['vpc_id'] and
(ec2utils.get_ec2_id_kind(item['id']) != 'vgw' or
item['id'] in vpn_connections))}
for vpn in six.itervalues(vpn_connections):
if vpn['vpn_gateway_id'] in destinations:
destinations[vpn['vpn_gateway_id']]['vpn_connection'] = vpn
return destinations
示例8: _apply_updates
# 需要导入模块: import six [as 别名]
# 或者: from six import itervalues [as 别名]
def _apply_updates(self, grad_func):
qs = self._var_list
self._define_variables(qs)
update_ops, infos = self._update(qs, grad_func)
with tf.control_dependencies([self.t.assign_add(1)]):
sample_op = tf.group(*update_ops)
list_attrib = zip(*map(lambda d: six.itervalues(d), infos))
list_attrib_with_k = map(lambda l: dict(zip(self._latent_k, l)),
list_attrib)
attrib_names = list(six.iterkeys(infos[0]))
dict_info = dict(zip(attrib_names, list_attrib_with_k))
SGMCMCInfo = namedtuple("SGMCMCInfo", attrib_names)
sgmcmc_info = SGMCMCInfo(**dict_info)
return sample_op, sgmcmc_info
示例9: collect
# 需要导入模块: import six [as 别名]
# 或者: from six import itervalues [as 别名]
def collect(self):
which = self.session.plugins.which_plugin(
type_name=self.plugin_args.type_name,
producers_only=True)
results = {}
for producer in which.collect():
# We know the producer plugin implements 'produce' because
# 'which_plugin' guarantees it.
self.session.logging.debug("Producing %s from producer %r",
self.type_name, producer)
for result in producer.produce():
previous = results.get(result.indices)
if previous:
previous.obj_producers.add(producer.name)
else:
result.obj_producers = set([producer.name])
results[result.indices] = result
return six.itervalues(results)
示例10: extract_futures
# 需要导入模块: import six [as 别名]
# 或者: from six import itervalues [as 别名]
def extract_futures(value, result):
"""Enumerates all the futures inside a particular value."""
if value is None:
pass
elif isinstance(value, futures.FutureBase):
result.append(value)
elif type(value) is tuple or type(value) is list:
# backwards because tasks are added to a stack, so the last one executes first
i = len(value) - 1
while i >= 0:
extract_futures(value[i], result)
i -= 1
elif type(value) is dict:
for item in six.itervalues(value):
extract_futures(item, result)
return result
示例11: main
# 需要导入模块: import six [as 别名]
# 或者: from six import itervalues [as 别名]
def main(self, args):
import aetros.const
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter,
prog=aetros.const.__prog__ + ' id')
parsed_args = parser.parse_args(args)
config = read_home_config()
try:
user = api.user()
except KeyNotConfiguredException as e:
self.logger.error(str(e))
sys.exit(1)
print("Logged in as %s (%s) on %s" % (user['username'], user['name'], config['host']))
if len(user['accounts']) > 0:
for orga in six.itervalues(user['accounts']):
print(" %s of organisation %s (%s)." % ("Owner" if orga['memberType'] == 1 else "Member", orga['username'], orga['name']))
else:
print(" Without membership to an organisation.")
示例12: AddSentence
# 需要导入模块: import six [as 别名]
# 或者: from six import itervalues [as 别名]
def AddSentence(self, ref_str, hyp_str):
"""Accumulates ngram statistics for the given ref and hyp string pair."""
ref_tokens = tuple(_Tokenize(self._unsegmenter(ref_str)))
self._num_ref_tokens += len(ref_tokens)
hyp_tokens = tuple(_Tokenize(self._unsegmenter(hyp_str)))
self._num_hyp_tokens += len(hyp_tokens)
for order_idx in range(self._max_ngram):
ref_counts = collections.Counter(NGrams(ref_tokens, order_idx + 1))
hyp_matches = collections.Counter()
hyp_count = 0
for x in NGrams(hyp_tokens, order_idx + 1):
hyp_count += 1
count = ref_counts[x]
if count:
# Clip hyp_matches so ngrams that are repeated more frequently in hyp
# than ref are not double counted.
hyp_matches[x] = min(hyp_matches[x] + 1, count)
self._hyp_ngram_matches[order_idx] += sum(six.itervalues(hyp_matches))
self._hyp_ngram_counts[order_idx] += hyp_count
示例13: _show_status_for_work
# 需要导入模块: import six [as 别名]
# 或者: from six import itervalues [as 别名]
def _show_status_for_work(self, work):
"""Shows status for given work pieces.
Args:
work: instance of either AttackWorkPieces or DefenseWorkPieces
"""
work_count = len(work.work)
work_completed = {}
work_completed_count = 0
for v in itervalues(work.work):
if v['is_completed']:
work_completed_count += 1
worker_id = v['claimed_worker_id']
if worker_id not in work_completed:
work_completed[worker_id] = {
'completed_count': 0,
'last_update': 0.0,
}
work_completed[worker_id]['completed_count'] += 1
work_completed[worker_id]['last_update'] = max(
work_completed[worker_id]['last_update'],
v['claimed_worker_start_time'])
print('Completed {0}/{1} work'.format(work_completed_count,
work_count))
for k in sorted(iterkeys(work_completed)):
last_update_time = time.strftime(
'%Y-%m-%d %H:%M:%S',
time.localtime(work_completed[k]['last_update']))
print('Worker {0}: completed {1} last claimed work at {2}'.format(
k, work_completed[k]['completed_count'], last_update_time))
示例14: _export_work_errors
# 需要导入模块: import six [as 别名]
# 或者: from six import itervalues [as 别名]
def _export_work_errors(self, work, output_file):
"""Saves errors for given work pieces into file.
Args:
work: instance of either AttackWorkPieces or DefenseWorkPieces
output_file: name of the output file
"""
errors = set()
for v in itervalues(work.work):
if v['is_completed'] and v['error'] is not None:
errors.add(v['error'])
with open(output_file, 'w') as f:
for e in sorted(errors):
f.write(e)
f.write('\n')
示例15: count_num_images
# 需要导入模块: import six [as 别名]
# 或者: from six import itervalues [as 别名]
def count_num_images(self):
"""Counts total number of images in all batches."""
return sum([len(v['images']) for v in itervalues(self.data)])