[Python-ideas] read-only attributes
Scott Dial
scott+python-ideas at scottdial.com
Tue Jan 4 03:13:02 CET 2011
On 1/3/2011 5:31 PM, Antoine Pitrou wrote:
> 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
>
> ?
>
s/4/Bar()/:
>>> class Foo:
... @property
... def foo(self):
... return Bar()
--
Scott Dial
scott at scottdial.com
scodial at cs.indiana.edu
More information about the Python-ideas
mailing list