Inheriting (subclass) of dict data attribute (copying)
Aaron S. Hawley
Aaron.Hawley at uvm.edu
Sun Jul 27 17:13:08 EDT 2003
Would be the most obvious (best in idiom) to overwrite the dictionary of
my derived dict class? The old school way is obvious to me.
TIA, /a
#!/usr/bin/env python
from UserDict import UserDict
class Old_Chickens(UserDict): ## old school
def __init__(self, chickens):
self.set_chickens(chickens)
def set_chickens(self, chickens):
self.data = chickens
class New_Chickens(dict): ## new school
def __init__(self, chickens):
self.set_chickens(chickens)
def set_chickens(self, chickens):
self = dict.__init__(self, chickens)
new_chickens = New_Chickens({'white': 12, 'brown': 8})
print new_chickens['white']
old_chickens = Old_Chickens({'white': 12, 'brown': 8})
print old_chickens['white']
--
PINE 4.55 Mailer - www.washington.edu/pine/
source-included, proprietary, gratis, text-based, console email client
More information about the Python-list
mailing list