I am trying to write a script that upgrades instances of a class. I have added new properties to my python product Class and I wish to run a method to check the old instances and add properties if necessary. I find that when I use the hasProperty('propname') method it always returns true. It appears that this method checks the 'Class' and not the actual 'Instances' for the existance of a property. So if I upgrade my class, I cant use this method to check for instances that are missing properties. Is this true?? It appears I have to actually raise an error to check for a property try: print instance.property else: instance.property='' This seems a bit silly. Am I doing anything wrong here Tom
Tom Cameron writes:
I am trying to write a script that upgrades instances of a class. I have added new properties to my python product Class and I wish to run a method to check the old instances and add properties if necessary. Why would you want to do that?
Normally, you have a default in your class. Only when the instance changes the property value, it will get its own copy of the property.
I find that when I use the hasProperty('propname') method it always returns true. Use "self.__dict__.has_key('propname')". Will work only in External Methods or other file system Python code....
Dieter
participants (2)
-
Dieter Maurer -
Tom Cameron