阅读背景:

创建一个被视为列表但具有更多功能的python类?

来源:互联网 

I have a class called dataList. It is basically a list with some metadata---myDataList.data contains the (numpy) list itself, myDataList.tag contains a description, etc. I would like to be able to make myDataList[42] return the corresponding element of myDataList.data, and I would like for Numpy, etc. to recognize it as a list (I.E., numpy.asarray(myDataList) returns a numpy array containing the data in myDataList). In Java, this would be as easy as declaring dataList as implementing the List interface, and then just defining the necessary functions. How would you do this in Python?I have a class called dataList. It is basically




你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: