当前位置: 首页>>代码示例>>Python>>正文


Python chain.append方法代码示例

本文整理汇总了Python中itertools.chain.append方法的典型用法代码示例。如果您正苦于以下问题:Python chain.append方法的具体用法?Python chain.append怎么用?Python chain.append使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在itertools.chain的用法示例。


在下文中一共展示了chain.append方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _maybe_merge

# 需要导入模块: from itertools import chain [as 别名]
# 或者: from itertools.chain import append [as 别名]
def _maybe_merge(self, n):
		from accelerator.g import slices
		if slices < 2:
			return
		fn = self.column_filename(n)
		sizes = [os.path.getsize(fn % (sliceno,)) for sliceno in range(slices)]
		if sum(sizes) / slices > 524288: # arbitrary guess of good size
			return
		offsets = []
		pos = 0
		with open(fn % ('m',), 'wb') as m_fh:
			for sliceno, size in enumerate(sizes):
				with open(fn % (sliceno,), 'rb') as p_fh:
					data = p_fh.read()
				assert len(data) == size, "Slice %d is %d bytes, not %d?" % (sliceno, len(data), size,)
				os.unlink(fn % (sliceno,))
				m_fh.write(data)
				offsets.append(pos)
				pos += size
		c = self._data.columns[n]
		self._data.columns[n] = c._replace(
			offsets=offsets,
			location=c.location % ('m',),
		) 
开发者ID:eBay,项目名称:accelerator,代码行数:26,代码来源:dataset.py

示例2: add

# 需要导入模块: from itertools import chain [as 别名]
# 或者: from itertools.chain import append [as 别名]
def add(self, colname, coltype, default=_nodefault, none_support=False):
		from accelerator.g import running
		assert running == self._running, "Add all columns in the same step as creation"
		assert not self._started, "Add all columns before setting slice"
		colname = uni(colname)
		coltype = uni(coltype)
		assert colname not in self.columns, colname
		assert colname
		typed_writer(coltype) # gives error for unknown types
		if none_support and coltype.startswith('bits'):
			raise DatasetUsageError("%s columns can't have None support" % (coltype,))
		self.columns[colname] = (coltype, default, none_support)
		self._order.append(colname)
		if colname in self._pcolumns:
			self._clean_names[colname] = self._pcolumns[colname].name
		else:
			self._clean_names[colname] = _clean_name(colname, self._seen_n) 
开发者ID:eBay,项目名称:accelerator,代码行数:19,代码来源:dataset.py

示例3: job_datasets

# 需要导入模块: from itertools import chain [as 别名]
# 或者: from itertools.chain import append [as 别名]
def job_datasets(job):
	"""All datasets in a job"""
	if isinstance(job, Dataset):
		job = job.job
	else:
		job = Job(job)
	fn = job.filename('datasets.txt')
	if not os.path.exists(fn):
		# It's not an error to list datasets in a job without them.
		return []
	with open(fn, 'r', encoding='utf-8') as fh:
		names = [line[:-1] for line in fh]
	res = []
	# Do this backwards to improve chances that we take advantage of cache.
	# (Names are written to datasets.txt in finish() order.)
	for name in reversed(names):
		res.append(Dataset(job, name))
	return list(reversed(res)) 
开发者ID:eBay,项目名称:accelerator,代码行数:20,代码来源:dataset.py

示例4: managers

# 需要导入模块: from itertools import chain [as 别名]
# 或者: from itertools.chain import append [as 别名]
def managers(self):
        managers = []
        seen_managers = set()
        bases = (b for b in self.model.mro() if hasattr(b, '_meta'))
        for depth, base in enumerate(bases):
            for manager in base._meta.local_managers:
                if manager.name in seen_managers:
                    continue

                manager = copy.copy(manager)
                manager.model = self.model
                seen_managers.add(manager.name)
                managers.append((depth, manager.creation_counter, manager))

                # Used for deprecation of legacy manager inheritance,
                # remove afterwards. (RemovedInDjango20Warning)
                manager._originating_model = base

        return make_immutable_fields_list(
            "managers",
            (m[2] for m in sorted(managers)),
        ) 
开发者ID:Yeah-Kun,项目名称:python,代码行数:24,代码来源:options.py

示例5: get_path_to_parent

# 需要导入模块: from itertools import chain [as 别名]
# 或者: from itertools.chain import append [as 别名]
def get_path_to_parent(self, parent):
        """
        Return a list of PathInfos containing the path from the current
        model to the parent model, or an empty list if parent is not a
        parent of the current model.
        """
        if self.model is parent:
            return []
        # Skip the chain of proxy to the concrete proxied model.
        proxied_model = self.concrete_model
        path = []
        opts = self
        for int_model in self.get_base_chain(parent):
            if int_model is proxied_model:
                opts = int_model._meta
            else:
                final_field = opts.parents[int_model]
                targets = (final_field.remote_field.get_related_field(),)
                opts = int_model._meta
                path.append(PathInfo(final_field.model._meta, opts, targets, final_field, False, True))
        return path 
开发者ID:Yeah-Kun,项目名称:python,代码行数:23,代码来源:options.py

示例6: get_path_from_parent

# 需要导入模块: from itertools import chain [as 别名]
# 或者: from itertools.chain import append [as 别名]
def get_path_from_parent(self, parent):
        """
        Return a list of PathInfos containing the path from the parent
        model to the current model, or an empty list if parent is not a
        parent of the current model.
        """
        if self.model is parent:
            return []
        model = self.concrete_model
        # Get a reversed base chain including both the current and parent
        # models.
        chain = model._meta.get_base_chain(parent)
        chain.reverse()
        chain.append(model)
        # Construct a list of the PathInfos between models in chain.
        path = []
        for i, ancestor in enumerate(chain[:-1]):
            child = chain[i + 1]
            link = child._meta.get_ancestor_link(ancestor)
            path.extend(link.get_reverse_path_info())
        return path 
开发者ID:Yeah-Kun,项目名称:python,代码行数:23,代码来源:options.py

示例7: show_requirements

# 需要导入模块: from itertools import chain [as 别名]
# 或者: from itertools.chain import append [as 别名]
def show_requirements(self, setup_key, requirements):
        """
        :param str setup_key: Name of corresponding key in 'setup()'
        :param setupmeta.RequirementsFile requirements:
        """
        content = "None,   # no auto-fill"
        names = []
        source_descriptions = []
        if requirements:
            for req_entry in requirements.reqs:
                if req_entry.requirement and not req_entry.is_ignored and req_entry.requirement not in names:
                    names.append(req_entry.requirement)
                    source_descriptions.append(req_entry.source_description)

        if names:
            longest_name = max(len(name) for name in names) + 5
            content = []
            for i, name in enumerate(names):
                content.append(self.represented_req(name, source_descriptions[i], longest_name))

            content = "[\n        %s\n    ]," % "\n        ".join(content).strip()

        print("    %s=%s" % (setup_key, content)) 
开发者ID:zsimic,项目名称:setupmeta,代码行数:25,代码来源:commands.py

示例8: get_console_scripts

# 需要导入模块: from itertools import chain [as 别名]
# 或者: from itertools.chain import append [as 别名]
def get_console_scripts(entry_points):
    """pygradle's 'entrypoints' are misnamed: they really mean 'consolescripts'"""
    if not entry_points:
        return None

    if isinstance(entry_points, dict):
        return entry_points.get("console_scripts")

    if isinstance(entry_points, list):
        result = []
        in_console_scripts = False
        for line in entry_points:
            line = line.strip()
            if line and line.startswith("["):
                in_console_scripts = "console_scripts" in line
                continue

            if in_console_scripts:
                result.append(line)

        return result

    return get_console_scripts(entry_points.split("\n")) 
开发者ID:zsimic,项目名称:setupmeta,代码行数:25,代码来源:commands.py

示例9: parent_recursive

# 需要导入模块: from itertools import chain [as 别名]
# 或者: from itertools.chain import append [as 别名]
def parent_recursive(self):
        """A list of parents, starting with the immediate parent"""
        parent_list = []
        parent = self.parent

        while parent:
            if parent:
                parent_list.append(parent)

            parent = parent.parent

        return parent_list 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:14,代码来源:bpy_types.py

示例10: children_recursive

# 需要导入模块: from itertools import chain [as 别名]
# 或者: from itertools.chain import append [as 别名]
def children_recursive(self):
        """A list of all children from this bone."""
        bones_children = []
        for bone in self._other_bones:
            index = bone.parent_index(self)
            if index:
                bones_children.append((index, bone))

        # sort by distance to parent
        bones_children.sort(key=lambda bone_pair: bone_pair[0])
        return [bone for index, bone in bones_children] 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:13,代码来源:bpy_types.py

示例11: children_recursive_basename

# 需要导入模块: from itertools import chain [as 别名]
# 或者: from itertools.chain import append [as 别名]
def children_recursive_basename(self):
        """
        Returns a chain of children with the same base name as this bone.
        Only direct chains are supported, forks caused by multiple children
        with matching base names will terminate the function
        and not be returned.
        """
        basename = self.basename
        chain = []

        child = self
        while True:
            children = child.children
            children_basename = []

            for child in children:
                if basename == child.basename:
                    children_basename.append(child)

            if len(children_basename) == 1:
                child = children_basename[0]
                chain.append(child)
            else:
                if children_basename:
                    print("multiple basenames found, "
                          "this is probably not what you want!",
                          self.name, children_basename)

                break

        return chain 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:33,代码来源:bpy_types.py

示例12: __new__

# 需要导入模块: from itertools import chain [as 别名]
# 或者: from itertools.chain import append [as 别名]
def __new__(cls, name, bases, classdict, **args):
        result = type.__new__(cls, name, bases, classdict)
        if bases and bases[0] is not StructRNA:
            from _weakref import ref as ref
            module = result.__module__

            # first part of packages only
            if "." in module:
                module = module[:module.index(".")]

            TypeMap.setdefault(module, []).append(ref(result))

        return result 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:15,代码来源:bpy_types.py

示例13: __setitem__

# 需要导入模块: from itertools import chain [as 别名]
# 或者: from itertools.chain import append [as 别名]
def __setitem__(self, key, val):
        dict.__setitem__(self, key, val)
        if key not in self.order:
            self.order.append(key) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:6,代码来源:bpy_types.py

示例14: link_to_here

# 需要导入模块: from itertools import chain [as 别名]
# 或者: from itertools.chain import append [as 别名]
def link_to_here(self, name='default', column_filter=None, override_previous=_no_override, filename=None):
		"""Use this to expose a subjob as a dataset in your job:
		Dataset(subjid).link_to_here()
		will allow access to the subjob dataset under your jid.
		Specify column_filter as an iterable of columns to include
		if you don't want all of them.
		Use override_previous to rechain (or unchain) the dataset.
		You can change the filename too, or clear it by setting ''.
		"""
		d = Dataset(self)
		if column_filter:
			column_filter = set(column_filter)
			filtered_columns = {k: v for k, v in d._data.columns.items() if k in column_filter}
			left_over = column_filter - set(filtered_columns)
			assert not left_over, "Columns in filter not available in dataset: %r" % (left_over,)
			assert filtered_columns, "Filter produced no desired columns."
			d._data.columns = filtered_columns
		from accelerator.g import job
		if override_previous is not _no_override:
			override_previous = _dsid(override_previous)
			if override_previous:
				# make sure it's valid
				Dataset(override_previous)
			d._data.previous = override_previous
			d._update_caches()
		d._data.parent = '%s/%s' % (d.job, d.name,)
		if filename is not None:
			d._data.filename = filename or None
		d.job = job
		d.name = uni(name)
		d._save()
		_datasets_written.append(d.name)
		return Dataset(d.job, d.name) 
开发者ID:eBay,项目名称:accelerator,代码行数:35,代码来源:dataset.py

示例15: _iterator

# 需要导入模块: from itertools import chain [as 别名]
# 或者: from itertools.chain import append [as 别名]
def _iterator(self, sliceno, columns=None):
		res = []
		not_found = []
		for col in columns or sorted(self.columns):
			if col in self.columns:
				res.append(self._column_iterator(sliceno, col))
			else:
				not_found.append(col)
		assert not not_found, 'Columns %r not found in %s/%s' % (not_found, self.job, self.name)
		return res 
开发者ID:eBay,项目名称:accelerator,代码行数:12,代码来源:dataset.py


注:本文中的itertools.chain.append方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。