我们从Python开源项目中,提取了以下20个代码示例,用于说明如何使用__builtin__.reversed()。
def remove_region(self, region_name): region_deleted_flag = False assert isinstance(region_name, basestring) try: LOG.debug("remove regions {0} from flavor {1}".format(region_name, str(self))) for region in reversed(self.flavor_regions): if region.region_name == region_name: self.flavor_regions.remove(region) region_deleted_flag = True if not region_deleted_flag: raise ErrorStatus(404, "Failed to remove region {0} from flavor id {1}".format( region_name, str(self.id))) except ErrorStatus as e: raise except Exception as exception: LOG.log_exception( "Failed to remove region {0} from flavor {1}".format( region_name, str(self)), exception) raise
def remove_tag(self, tag_name): deleted_flag = False assert isinstance(tag_name, basestring) try: LOG.debug("remove tag {0} from flavor {1}".format(tag_name, str(self))) for tag in reversed(self.flavor_tags): if tag.key_name == tag_name: self.flavor_tags.remove(tag) deleted_flag = True if not deleted_flag: raise ErrorStatus(404, "Failed to remove tag {0} from flavor id {1}".format( tag_name, str(self.id))) except ErrorStatus as e: raise except Exception as exception: LOG.log_exception( "Failed to remove tag {0} from flavor {1}".format( tag_name, str(self)), exception) raise
def remove_extra_spec(self, extra_spec_key_name): deleted_flag = False assert isinstance(extra_spec_key_name, basestring) try: LOG.debug("remove extra_spec {} from flavor {}".format(extra_spec_key_name, str(self))) for extra_spec in reversed(self.flavor_extra_specs): if extra_spec.key_name == extra_spec_key_name: self.flavor_extra_specs.remove(extra_spec) deleted_flag = True if not deleted_flag: # no need to raise in delete not found LOG.debug( "Failed to remove extra_spec {0} from flavor id {1}".format( extra_spec_key_name, str(self.id))) except ErrorStatus as e: raise except Exception as exception: LOG.log_exception( "Failed to remove extra_spec {0} from flavor {1}".format(extra_spec_key_name, str(self)), exception) raise
def reversed(x): try: return __builtin__.reversed(x) except TypeError: return reversed(list(x))
def string_to_natural(s, alphabet=None): if alphabet is None: assert not s.startswith('\x00') return int(s.encode('hex'), 16) if s else 0 else: assert len(set(alphabet)) == len(alphabet) assert not s.startswith(alphabet[0]) return sum(alphabet.index(char) * len(alphabet)**i for i, char in enumerate(reversed(s)))
def ex_args(cls, f): c = f.func_code varnames_count, varnames_iter = c.co_argcount, iter(c.co_varnames) args = tuple(itertools.islice(varnames_iter, varnames_count)) res = { a : v for v,a in zip(reversed(f.func_defaults or []), reversed(args)) } try: starargs = next(varnames_iter) if c.co_flags & cls.CO_VARARGS else "" except StopIteration: starargs = "" try: kwdargs = next(varnames_iter) if c.co_flags & cls.CO_VARKEYWORDS else "" except StopIteration: kwdargs = "" return args, res, (starargs, kwdargs)
def reversed(data): if not isinstance(data, list): data = list(data) return data[::-1]
def reversed(data): if not isinstance(data, list): data = list(data) reversed_data = [] for index in xrange(len(data)-1, -1, -1): reversed_data.append(data[index]) return reversed_data # --- sorted() from Python 2.4 ---
def remove_tenant(self, tenant_id): assert isinstance(tenant_id, basestring) try: LOG.debug("remove tenants {0} from flavor {1}".format(tenant_id, str(self))) for tenant in reversed(self.flavor_tenants): if tenant.tenant_id == tenant_id: self.flavor_tenants.remove(tenant) except Exception as exception: LOG.log_exception( "Failed to remove tenant {0} from flavor {1}".format( tenant_id, str(self)), exception) raise