Changing the class of an instance

Alex cut_me_out at hotmail.com
Mon Jul 17 14:31:28 EDT 2000


>     I don't think "confusing" is the right word. Although I'm fairly
> certain I won't get the words right: It destroys the...  maybe the
> word is "encapsulation" or "modularity" or something - it means that
> you cannot verify things are correct by just looking at things
> locally. 

You're probably right, I don't know much of the jargon.

> Not sure what sort of debugging we're referring to. If you're trying
> to figure out how to do something, as opposed to writing code meant to
> be used later, that's different.

True, that's what I was trying to do, so the changing of the class was
only happening on a very limited and interactive level (and it still got
a bit confusing at times. :)

> Possibly I missed it, but I haven't seen any reason given why changing
> __class__ is better than creating a new instance

Well, if you want to do it by creating a new instance, you have to make
some sort of copy constructor.  Unless you automate the process so that
it copies every attribute of the instance, you are bound to forget one
at some point.

Alex.



More information about the Python-list mailing list