'Is there a pythonic way to add a text description to instance objects?
I think it is best to explain what I want by giving the way I'm currently doing it:
class Car:
def __init__(self, vehicle):
self.vehicle = vehicle
def set_driver_temperament(self, text):
self._driver_temperament = text
def get_driver_temperament(self):
return self._driver_temperament
driver1 = Car('Toyota Camry')
# A lot of code here
driver1.set_driver_temperament("""
Cool Headed
Financial Wise""")
driver2 = Car('Ferrari')
# A lot of code here
driver2.set_driver_temperament("""
A**hole
Too much money, too little brains""")
I just want to know if there is a more pythonic way of doing this? I checked online, but I cannot find anything
Edit:
So the example is not too clear, but the driver_temperament can not be set at the initial declaration.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
