Skip to content

Instantly share code, notes, and snippets.

@dmiro
Created February 13, 2015 17:17
Show Gist options
  • Select an option

  • Save dmiro/8a38c3af11654d24141b to your computer and use it in GitHub Desktop.

Select an option

Save dmiro/8a38c3af11654d24141b to your computer and use it in GitHub Desktop.
Para tener un read-only @Property decorator DEBES heredar del nuevo estilo de clases "object"
To have a 'read-only' property in a class you can make use of the @property decoration, you'll need to inherit from object when you do so to make use of the new-style classes.
Example:
>>> class A(object):
... def __init__(self, a):
... self.__a = a
... @property
... def a(self):
... return self.__a
...
>>> a = A('test')
>>> a.a
'test'
>>> a.a = 'pleh'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: can't set attribute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment