I have a Python object which has certain attributes that are set after the constructor is called. For example,
def Student(object):
def __init__(name, address=None):
self.name = name
self.address = address
stud = Student("John")
stud.address = "123 Main St. New York, NY"
I would like to be able to have a function be called when the address attribute is set which will do things such as reformat the address or do a lookup and add in the zip code, etc. Is there a way to accomplish this within the object’s definition or should I just have to do that myself every time I set the address attribute?
What you probably need is a property concept.
See this link for more details: http://snippets.dzone.com/posts/show/954