On 6/14/05, Vero <[EMAIL PROTECTED]> wrote: > Hi. My name is Veronica, I am a master student at UNAM. I am working on > something related to Artificial Inteligence and I have been looking for the > most appropriated programming language to implement my algorithms. I found > python to be very close to what I need, but there are still a couple of > details that I haven't been able to solve. > > First, (and most important) I would like to be able to dynamically modify > the classes from which a class inherits. I haven't found any way to do it > with the language as it is. If there is a way, any suggestion will be truly > appreciated. If I had to modify the source code to achieve this, I hope > that you could give me some hints; I have an idea of how something like this > could be achieved but since I don't know deeply the python sourcode I could > get lost.
I wonder if assignment to __class__ (for instances) or to __bases__ (for classes) is what you are looking for? >>> class C: def foo(self): print "foo" >>> class D: def foo(self): print "D.foo" >>> x = C() >>> x.__class__ = D >>> x.foo() D.foo >>> x.__class__ = C >>> x.foo() foo >>> > Second, since my program will be modifying classes during run time, I would > like to have a way to write on a file the python code that would have > defined the class with the functions and attributes as they were left, just > as if it had been writen like that at the very begining. I need it to be > python code because I will be using that latter. Maybe I will have to solve > this second problem by myself but I just wrote in case anybody had a good > idea. That one's not so easy; there's no standard solution for this problem. I recommend that you follow Aahz' suggestion of asking on c.l.py instead. -- --Guido van Rossum (home page: http://www.python.org/~guido/) _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com