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. You need to identify what class the object will be an instance of before loading it. Which, if you're using XML tags like <Building type="House"> or <House>, shouldn't be very difficult to do.


-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting and sweating as you run through my corridors... How can you challenge a perfect, immortal machine?"



_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Reply via email to