Python 2.2, creating new types from base types
Jason Orendorff
jason at jorendorff.com
Fri Jan 18 03:20:04 EST 2002
> I'll give your approach a try.
I've been thinking about it.
Depending on what you're modeling, you may want to model
each "layer" of the "tree" with a separate class...
class Catalog:
# Topmost dictionary-like object
# Use whatever data model makes sense for this level
def __getitem__(self, key):
# Consult the data model...
# Return a ProductLine object
class ProductLine:
# Use whatever data model makes sense for this level
def __getitem__(self, key):
# Consult the data model...
# Insert fuzzy matching code here...
# Return a Model object
class Model:
# etc.
The classes that *need* all the dictionary features can
subclass UserDict; the others shouldn't...
I think you might get more mileage out of this approach.
It's so much more down-to-earth. :-) But of course it
depends on what you're doing.
## Jason Orendorff http://www.jorendorff.com/
More information about the Python-list
mailing list