const in Python

Gene Chiaramonte gchiaramonte at ibl.bm
Tue Feb 8 07:27:04 EST 2000


I think this is a very important issue. Especially when you are distributing
apps with python as an embedded scripting language. Case insensitivity and
constants are two things I think are very necessary in a scripting language.
Luckily, both can be enforced in the script editor.

Gene

> -----Original Message-----
> From: python-list-admin at python.org
> [mailto:python-list-admin at python.org]On Behalf Of Fredrik Lundh
> Sent: Tuesday, February 08, 2000 6:05 AM
> To: python-list at python.org
> Subject: Re: const in Python
>
>
> Anders M Eriksson <anders.eriksson at morateknikutveckling.se> wrote:
> >> > 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.
>
> so you don't trust yourself enough to avoid overwrite
> anything using a certain name convention (UPPERCASE
> is pretty much standard in Python land), but are 100%
> convinced you won't ever overwrite the 'const' variable?
>
> interesting ;-)
>
> </F>
>
>
> --
> http://www.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list