[Python-ideas] read-only attributes

Antoine Pitrou solipsis at pitrou.net
Mon Jan 3 23:31:11 CET 2011


On Mon, 03 Jan 2011 14:18:42 -0800
"K. Richard Pixley" <rich at noir.com> wrote:
> 
> class Foo(object):
>      @read-only
>      size = 4

What's wrong with:

>>> class Foo:
...     @property
...     def foo(self):
...         return 4
... 
>>> Foo().foo
4
>>> Foo().foo = 5
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: can't set attribute

?





More information about the Python-ideas mailing list