vendredi 8 juillet 2016

How to call a variabe of an inner class correctly

I would like to set the value of an inner class and call it from out of any class. I use the same thing for the (outer)class, the value gets changed in the set def, but outside of that function it ooks like is hasnt changed.

my code looks like this

class car(vehicle):
    __vehicle_kind = "car"
    __nb_of_wheels = 4
    __nb_of_doors = 2

    def showKind(self):
        return self.__vehicle_kind

    def showNbOfWheels(self):
        return self.__nb_of_wheels

    def showNbOfDoors(self):
        return self.__nb_of_doors

    class wheels(vehicle):
        wheel_color = "grey"
        wheel_diametre = "16"

        def setWheelColor(self, color):
            self.wheel_color = color
            print self.wheel_color

        def showWheelColor(self):
            return self.wheel_color

I set and call the showWheelColor with:

new.wheels().setWheelColor(wheel_color)
print new.wheels().showWheelColor()

but the show returns the old value. How to make this work correctly?

Aucun commentaire:

Enregistrer un commentaire