On Mar 24, 2005, at 18:07, Ismael Garrido wrote:
Hello.
I have a program that saves/loads to/from XML. I have a main class Building, and a subclass House(Building). When I save the code I instruct each object to save itself to XML (using ElementTree), so House adds itself to the XML tree.
My problem is when I load the XML. Before having subclasses what I did was to send the XML object (again in ElementTree) to the object and let itself load. Now, with subclasses, if I send the House XML to Building I get a Building instance, when I need a House instance.
You can't make an object transform into an object of a different class
Are you referring to a Python object? If so you may assign a class to the object's __class__ attribute.
class A:pass
class B:pass
b = b()
print b.__class__ # displays <class __main__.B at 0x011BB9C0>
b.__class__ = A
print b.__class__ # displays <class __main__.A at 0x011BBA20>
[snip]
mailto:[EMAIL PROTECTED]
510 558 3275 home
720 938 2625 cell
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor