modifying source at runtime - jython case
Alan Kennedy
alanmk at hotmail.com
Sun Nov 6 13:30:32 EST 2005
[Jan Gregor]
> Following try showed me that instances aren't affected by
> modification in class definition.
Is this more like what you mean?
c:\>jython
Jython 2.1 on java1.4.2_09 (JIT: null)
Type "copyright", "credits" or "license" for more information.
>>> class a:
... def test(self):
... print "First"
...
>>> x = a()
>>> x.test()
First
>>> def test(self):
... print "Second"
...
>>> a.test = test
>>> x.test()
Second
>>>
If that's what you're thinking, you should read up on class objects,
instance objects and method objects.
http://docs.python.org/tut/node11.html#SECTION0011320000000000000000
[Jan Gregor]
> my typical scenario is that my swing application is running, and
> i see some error or chance for improvement - modify sources of app,
> stop and run application again.
You're really talking about an IDE here.
> so task is to reload class defitions (from source files) and modify
> also existing instances (their methods).
You can modify the behaviour of all existing instances of a class, e.g.
their methods, by modifying the class itself. Any reference to the
method on the instance will resolve to the method definition from its
class, provided you haven't overwritten the method on the individual
instance. Resolving the method is done at invocation time, because
python/jython is a late-binding language.
Any closer?
--
alan kennedy
------------------------------------------------------
email alan: http://xhaus.com/contact/alan
More information about the Python-list
mailing list