python - can properties use array syntax? -
can use either property
or @property
create uses array syntax? in code, like:
x = exampleclass() x.y[6] #x.y property, 6 passed arg getter function
thanks
you can making y
container type:
>>> class a(object): ... def __getitem__(self, index): ... return 2 * index ... >>> = a() >>> a[3] 6 >>> class exampleclass(object): ... def __init__(self): ... self.y = a() ... >>> x = exampleclass() >>> x.y[6] 12
Comments
Post a Comment