Re: [Tutor] Changing a class into a subclass

2005-03-25 Thread Alan Gauld
> > single instance (or indeed no instances because you could > > use a static method... or get really fancy and create a > > meta-class!). > > or make it a static method of Building Yes that's actually what I meant, but reading it back it sounds like I meant static Factory method Ho hum.

Re: [Tutor] Changing a class into a subclass

2005-03-24 Thread Kent Johnson
Ismael Garrido wrote: But there's something that I couldn't understand. In the following code, my guess would be that "I'm back from the death" would never get printed... but it is... and twice! Why? It's printed every time B.pong() is called, just as "Pong" is. You print each one twice - no mys

Re: [Tutor] Changing a class into a subclass

2005-03-24 Thread Ismael Garrido
Alan Gauld wrote: Absolutely, looks like you answered your own question... :-) But if you want an OOP approach thre are some things to try. First you can create a BuildingFactory class that has a single instance (or indeed no instances because you could use a static method... or get really fancy an

Re: [Tutor] Changing a class into a subclass

2005-03-24 Thread Kent Johnson
Alan Gauld wrote: But if you want an OOP approach thre are some things to try. First you can create a BuildingFactory class that has a single instance (or indeed no instances because you could use a static method... or get really fancy and create a meta-class!). or make it a static method of Build

Re: [Tutor] Changing a class into a subclass

2005-03-24 Thread Alan Gauld
> 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 > b.__class__ = A > print b.__class__ # displays Interesting Bob, but presumably that doesn't change the internal sta

Re: [Tutor] Changing a class into a subclass

2005-03-24 Thread Alan Gauld
> > 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 loadin

Re: [Tutor] Changing a class into a subclass

2005-03-24 Thread Bob Gailer
At 10:30 AM 3/24/2005, Max Noel wrote: 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 Hou

Re: [Tutor] Changing a class into a subclass

2005-03-24 Thread Kent Johnson
Max Noel wrote: 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

Re: [Tutor] Changing a class into a subclass

2005-03-24 Thread Max Noel
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 pro

[Tutor] Changing a class into a subclass

2005-03-24 Thread Ismael Garrido
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 subcla