Constants in Python

Brent W. Hughes at
Tue Sep 7 07:06:58 CEST 2004

Warning:  Newbie at work!

I was planning to write some code something like this:

class CTree:
    LEAFSIZE = 4
    LeafNode = [None] * LEAFSIZE
    def Add(self,Node,SubTree):
        Key1 = Node[KEY]

But then I realized that the last line (and many more similar lines)
would probably need to be writen thusly:

        Key1 = Node[CTree.KEY]

I find this a little ugly, not to mention more typing.  I suppose
I could move these lines:

    LEAFSIZE = 4

out of the class and make them global, but this kind of runs
against the grain.

Is there another way to deal with "constants"?


More information about the Python-list mailing list