Ok, I'm really really new to Python. I've installed Python 2.7 and is using IDLE (GUI).
I just wrote 2 classes, Car and CarsDB, but I can't load them together to use them.
class Car(object):
'A car with its own information like make, year, model, price.'
def __init__(self, mk, md, yr, pr):
'Initializes car with the given information'
self.make = mk
self.model = md
self.year = yr
self.price = pr
def showInfo(self):
'Shows the car information such as make, model, year, price'
print "Make: %s\nModel: %s\nYear: %d\nPrice: $%.2f\n" \
% (self.make, self.model, self.year, self.price)
class CarsDB(object):
'A car DB with information such as make, model, year, price of each car.'
def __init__(self):
'Initialization'
self.db = []
def addCar(self, car):
'Add a car to the DB'
db.append(car)
def showDB(self):
"Shows the car's database"
for eachCar in db:
print eachCar,
This is what I get when I try to import those 2 classes to use (creating instances) in IDLE (the default GUI):
>>> import Car
>>> car = Car('Honda','Civic',2009,20000)
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
car = Car('Honda','Civic',2009,20000)
TypeError: 'module' object is not callable
>>> import CarsDB
>>> db = CarsDB()
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
db = CarsDB()
TypeError: 'module' object is not callable
>>>
Can someone tell me what I'm doing wrong? Or how to correctly load/use the classes?