DRY and class variables

egbert egbertum at xs4all.nl
Thu Sep 8 05:55:02 EDT 2011

My classes correspond to sql tables.
In these classes I want to have several class variables
that refer to data that are common to all instances.

The assignment statements for the class variables are the same
in all classes, except that of these instructions needs the name
of the class itself. That name is used to read a file with meta-data.

So what I have now is something like this (simplified):

class TableOne(object):
    m = Metadata('TableOne')
    def __init__(self):

class TableTwo(object):
    m = Metadata('TableTwo')
    def __init__(self):

I have tried:
- to eliminate the class name argument, but in this phase of the
  object creation __class__ and __name__ are not available
- to move the two statements to a superclass, but the class variables
  come in the superclass namespace, not in the subclass namespace.

Any ideas ?
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

More information about the Python-list mailing list