Newbie class instance tracking system

Michael McGovern mmcgover at
Wed May 9 21:57:27 CEST 2001

I am new to Python and I am having trouble with the following code.  In short,
Why doesn't it work?  I thought that variable names "spring into existence" in
a similar fasion to perl...

# I want to keep track of all the unique cars per company without repeating
# I get this error:
#Traceback (innermost last):
#  File "", line 14, in ?
#    prelude = Maker(carName='prelude',carCompany='Honda')
#  File "", line 11, in __init__
#    Maker.all_cars[carCompany].append(carName)
#KeyError: Honda

class Maker:

	def __init__(self,carName=None,carCompany=None):
		self.carName = carName
		self.carCompany = carCompany

                # in perl, I would push(@{$all_cars{$carCompany}},$carName)

prelude = Maker(carName='prelude',carCompany='Honda')
accord = Maker(carName='accord',carCompany='Honda')		

Thanks in advance,
mmcgover at pender dot ee dot upenn dot edu

More information about the Python-list mailing list