No Thoughts about Everything

Dave Brueck dave at pythonapocrypha.com
Wed Feb 25 10:55:45 EST 2004


Bernhard wrote:
[snip]
> while using Java. I kindly ask for help to transfer that simple, single
> line intelligent to python in the best possible way:
>
> static final double c=2.99792458e8;
> How can I create such a "class constant" (static final / recipe 5.15 and
> 5.6 in one) in python as short as possible?

class Foo:
  BAR = 10

Voila! BAR is now a "class constant" - shared among all instances of the class
Foo (in theory it's not a constant, but in practice it is :) ).

HTH,
Dave





More information about the Python-list mailing list