跳转到主要内容

一个懒加载的、可切片的迭代器。

项目描述

切片器

一个懒加载的、可切片的迭代器

将其想象成一个“可重复使用”且有长度的生成器。

请参阅文档以获取示例和API参考。

build status Documentation Status

安装

在任何平台上,使用pip或conda。

pip install slicerator

conda install -c conda-forge slicerator

示例

from slicerator import Slicerator

@Slicerator.from_class
class MyLazyLoader:
    def __getitem__(self, i):
        # this method will be wrapped by Slicerator, so that it accepts slices,
        # lists of integers, or boolean masks. Code below will only be executed
        # when an integer is used.

        # load thing number i
        return thing

    def __len__(self):
        # do stuff
        return number_of_things


# Demo:
>>> a = MyLazyLoader()
>>> s1 = a[::2]  # no data is loaded yet
>>> s2 = s1[1:]  # no data is loaded yet
>>> some_data = s2[0]

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源代码分发

slicerator-1.1.0.tar.gz (38.3 kB 查看哈希值)

上传时间 源代码

构建分发

slicerator-1.1.0-py3-none-any.whl (10.3 kB 查看哈希值)

上传时间 Python 3