3 Defining Instance Methods

If we add the following method to the Users class definition, this will do the trick:

    def updateValues(self, dict):
        if not dict.has_key['LAST_MOD']:
            dict = dict.copy()
            dict['LAST_MOD'] = SYSDATE
        return PyDO.updateValues(self, dict)

All it does is say, if they didn't specify a value for LAST_MOD (we assume here that if they specified it, they did for good reason), we make a copy of the dict (in the case that they still hold a reference to it, we don't want to screw it up) and set LAST_MOD to SYSDATE, and subsequently call our baseclasses version of updateValues.

This brings us to methods, of which there are two flavors, static and instance. Python itself doesn't have the notion of static methods, but for certain applications (specifically PyDO), they can be made available and incredibly useful.

To create a regular method, just write it as if everything was normal in python land. Nothing big to mention here. It will apply to instances of data classes and you can get an unbound verion by saying class.method just as in regular Python.