I am using a sample from my book for testing a car class. I get this error and I am not sure why. I am only giving one argument that I can tell.
Here is my error code:
Traceback (most recent call last):
File "G:\Python_Stuff\car.py", line 79, in <module>
TypeError: getVIN() takes exactly 1 argument (2 given)

This is the code:

class Car:

    def __init__(self):# VIN, Make, Model, Color, Year, Price):
        self._VIN = ' ' #VIN
        self._Make = ' ' #Make
        self._Model = ' ' #Model
        self._Color = ' ' #Color
        self.setYear(' ')

    def getOwner(self):
        return self._Owner

    def setVIN(self, VIN):
        self._VIN = VIN

    def getVIN(self):
        return self._VIN

    def setMake(self, Make):
        self._Make = Make

    def getMake(self):
        return self._Make

    def setModel(self, Model):
        self._Model = Model

    def getModel(self):
        return self._Model

    def setColor(self, Color):
        self._Color = Color

    def getColor(self):
        return self._Color

    def setYear(self, Year):
        if Year >= 1980:
            self._Year = Year
            print('invalid input for year, set to default value.')
            self._Year = 1980

    def getYear(self):
        return Year

    def setPrice(self, Price):
        if Price >= 5000:
            self._Price = Price
            print("invalid input for price, set to default value.")
            self._Price = 5000

    def __str__(self):
        display = "The car with the VIN '" + str(self._VIN) + "' is a '"
        display += str(self._Year) + "' " + str(self._Color) + " " + str(self._Make) + "\n"
        display += str(self._Model) + " with the price of '$" + str(self._Price) + "'"
        display += "\nOwner: " + str(self._Owner)
        return display

#Test class Car code test
if __name__ == '__main__':
  myCar = Car()
  print myCar
  print myCar

  print myCar

  print myCar

  print myCar

  print myCar

Consider using python property builtin function. It is built for that.
Consider raising exception when the price is invalid.
Consider using new style classes if you run python 2.x.
If you have questions about that do not hasitate to ask...

I do not know what book you have, but it is either a java book or a very generic object orientated learning book. Python does not need getters-setters in most of the cases. Or a bad python book.

Why should VIN be a managed attribute? Why do you attempt to set the attribute with a getter?

All the questions ...

Getters and setters are evil. Evil, evil, I say! Python objects are not Java beans. Do not write getters and setters. This is what the ‘property’ built-in is for. And do not take that to mean that you should write getters and setters, and then wrap them in ‘property’.


The link over is follow up from python is Not java.

Edited 6 Years Ago by snippsat: n/a

thanks a lot for the help. This is a class for object programming.

This question has already been answered. Start a new discussion instead.