Previous topic

propy.str_property

Next topic

propy.weakref_property

This Page

propy.index_property

propy.index_property(index)[source]

Creates a named setter and getter for an object that is a subclass of a list or array. To use, place the method within a class’s scope.

Parameters:
name : str

The name of the object

index : int

The index associated with the name.

Examples

The following could be done to map a 2D array to names [x, y]:

>>> class Class(list):
...     x = index_property('x', 0) # obj.x can be used in lieu of obj[0]
...     y = index_property('y', 1) # obj.y can be used in lieu of obj[1]
...
...     def __init__(self, x, y):
...         self.extend([x, y])