DRY and class variables

E

egbert

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')
m.do_something()
def __init__(self):
etc

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

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 ?
e
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,708
Messages
2,569,346
Members
44,650
Latest member
LuckyVivo

Latest Threads

Top