从python切片对象开始和停止

m_a*_*ber 6 python

我正在使用scipy ndimage模块,我正在使用find_objects函数,它返回一个切片对象.现在我想读取这个切片对象并从中获取开始和结束索引.但是,我找不到这样做的方法.

fragments = ndimage.find_objects(labels)
print fragments[0][0]
> slice(0L, 832L, None)
Run Code Online (Sandbox Code Playgroud)

如何将开始和结束索引存储为我的python代码中的变量.

任何帮助将不胜感激.提前致谢.

Ant*_*ala 10

a的成员slicestart,stepstop:

切片对象具有只读数据属性start,stop并且step仅返回参数值(或其默认值).


因此很简单:

>>> sl = slice(0L, 832L)
>>> sl
slice(0L, 832L, None)
>>> start = sl.start
>>> stop = sl.stop
>>> start, stop
(0L, 832L)
Run Code Online (Sandbox Code Playgroud)