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

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -