No Thoughts about Everything

Keel Thaan kmt at MailCentro.zzn.com
Wed Feb 25 15:31:55 EST 2004


b-blochl wrote:

> static final double c=2.99792458e8;
> 
> That is the speed of light in vacuum in scientific (exponential) 
> notation. I use it in a class as a class variable. That means it will be 
> shared as a single copy of a variable among all of the objects 
> instantiated from that class. That is the meaning of the modifier 
> "static". With final I make it to a constant, that cannot changed by any 
> code. (double is self speaking, it is not necessary in python - as 
> anyone knows.) I dont like to use c as global variable.

> So, here again my Question:
> How can I create such a "class constant" (static final / recipe 5.15 and 
> 5.6 in one) in python as short as possible?


This will create c as an unmodifiable attribute:

	c = property(lambda self: 2.99792458e8)


Does that do what you want?




More information about the Python-list mailing list