design question, metaclasses?

Darren Dale dsdale24 at
Sat Apr 11 20:15:03 CEST 2009

I am working on a project that provides a high level interface to hdf5
files by implementing a thin wrapper around h5py. I would like to
generalize the project so the same API can be used with other formats,
like netcdf or ascii files. The format specific code exists in File,
Group and Dataset classes, which I could reimplement for each format.
But there are other classes deriving from Group and Dataset which do
not contain any format-specific code, and I would like to find a way
to implement the functionality once and apply uniformly across
supported formats. This is really abstract, but I was thinking of
something along the lines of:

format1.Group # implementation of group in format1
format2.Group # ...
Base.DerivedGroup # base implementation of DerivedGroup, not directly
format1.DerivedGroup = Base.DerivedGroup(format1.Group) # useful
format2.DerivedGroup = Base.DerivedGroup(format2.Group) # useful

Could anyone please offer a comment, is this an appropriate use of
metaclassing, or is there maybe an easier/better alternative?

More information about the Python-list mailing list