可能是一个 n00b 问题,但我目前有一个实现迭代器的类,所以我可以做类似的事情
Might be a n00b question, but I currently have a class that implements an iterator so I can do something like
for i in class():
但我希望能够像索引一样访问类
but I want to be able to access the class by index as well like
class()[1]
我该怎么做?
谢谢!
同时实现 __iter__() 和 __getitem__() 等方法.
Implement both __iter__() and __getitem__() et alia methods.
这篇关于迭代器和索引可访问的 Python 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何在python中的感兴趣区域周围绘制一个矩形How to draw a rectangle around a region of interest in python(如何在python中的感兴趣区域周围绘制一个矩形)
如何使用 OpenCV 检测和跟踪人员?How can I detect and track people using OpenCV?(如何使用 OpenCV 检测和跟踪人员?)
如何在图像的多个矩形边界框中应用阈值?How to apply threshold within multiple rectangular bounding boxes in an image?(如何在图像的多个矩形边界框中应用阈值?)
如何下载 Coco Dataset 的特定部分?How can I download a specific part of Coco Dataset?(如何下载 Coco Dataset 的特定部分?)
根据文本方向检测图像方向角度Detect image orientation angle based on text direction(根据文本方向检测图像方向角度)
使用 Opencv 检测图像中矩形的中心和角度Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 检测图像中矩形的中心和角度)