For example:
class Car:
pass
jeep = Car()
jeep.color = 'blue'
This is perfectly legal and runs fine. I understand that python is pretty dynamic but doesn’t this violate some principle of oop?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
http://docs.python.org/tutorial/classes.html#odds-and-ends
To dynamically set up the fields and value when they can only be known at run time.
Python does not prevent you from dynamically creating instance properties, though you can decide not to do so if you have no very good reason to do so. Python is quite a powerful language, though care must be excercise to avoid abusing this sort of power to do crazy things with it’s flexibility.