一个懒散的装载,花俏的切片机。
slicerator的Python项目详细描述
一个懒散的装载,花哨的可滑动部件
把它想象成一个“可重用”并且有长度的生成器。
Please see the documentation用于 示例和API引用。
安装
在任何平台上,使用pip或conda。
pip install slicerator
或
conda install -csoft-matter slicerator
示例
fromsliceratorimportSlicerator@Slicerator.from_classclassMyLazyLoader: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 ireturnthingdef__len__(self):# do stuffreturnnumber_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]