const in Python
Anders M Eriksson
anders.eriksson at morateknikutveckling.se
Tue Feb 8 04:25:36 EST 2000
On Tue, 8 Feb 2000 10:11:31 +0900, Tom Holroyd <tomh at po.crl.go.jp>
wrote:
>On Mon, 7 Feb 2000, Gordon McMillan wrote:
>
>> Anders M Eriksson writes:
>> If you are truly concerned, you could make them attributes of
>> a class that prohibits setattr. But generally naming
>Right, like this:
>
>class ReadOnly:
> def __setattr__(self, name, value):
> if self.__dict__.has_key(name):
> raise TypeError, 'value is read only'
> self.__dict__[name] = value
>
>>>> const = ReadOnly()
>>>> const.x = 5
>>>> const.x = 9
>TypeError: value is read only
>
Thank You! I love your class and it will from now be in every program
I make.
// Anders
--
Thought I could organise freedom
how Scandinavian of me
More information about the Python-list
mailing list