Constants in Python

Andrew Koenig ark at acm.org
Tue Sep 7 01:21:04 EDT 2004


"Brent W. Hughes" <brent.hughes at comcast.net> wrote in message 
news:Slb%c.389920$%_6.21712 at attbi_s01...

> I was planning to write some code something like this:

> class CTree:
>    LEAFSIZE = 4
>    LeafNode = [None] * LEAFSIZE
>    KEY,DATA,LEFT,RIGHT = range(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]

How about this?

            Key1 = Node[self.KEY]

Seems consistent with other class-relative usages.





More information about the Python-list mailing list