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?
Thanks.
You can subclass list and provide additional methods:
CustomList inherits the methods of Python’s ordinary lists and you can easily let it implement further methods and/or attributes.