modifying source at runtime - jython case
Jan Gregor
gregor.jan at NOSPAMquick.cz
Sat Nov 5 09:34:14 EST 2005
In article <b11bf.18224$R5.1804 at news.indigo.ie>, Alan Kennedy wrote:
> [Jan Gregor]
>> I want to apply changes in my source code without stopping jython
>> and JVM. Preferable are modifications directly to instances of
>> classes. My application is a desktop app using swing library.
>>
>> Python solutions also interest me.
>>
>> Solution similiar to "lisp way" is ideal.
>
> OK, I'll play 20 questions with you.
>
> How close is the following to what you're thinking?
I see.
Following try showed me that instances aren't affected by
modification in class definition.
but this helped
x.test = a().test OR x.test = y.test
The only thing left is how to initiate modification, it's a
swing application and i think interp.exec don't stop until
it's done. Maybe somehow call it from jython itself - but need
to pass PythonInterpreter instance.
Thanks.
class a:
def test(self):
print 'first'
x= a()
class a:
def test(self):
print 'second'
y= a()
x.test()
y.test()
>
> begin SelfMod.java -------------------------------------------
> //************************************************************
> import org.python.util.PythonInterpreter;
> import org.python.core.*;
>
> class SelfMod
> {
>
> static String my_class_source =
> "class MyJyClass:\n" +
> " def hello(self):\n" +
> " print 'Hello World!'\n";
>
> static String create_instance = "my_instance = MyJyClass()\n";
>
> static String invoke_hello = "my_instance.hello()";
>
> static String overwrite_meth =
> "def goodbye():\n"+
> " print 'Goodbye world!'\n" +
> "\n" +
> "my_instance.hello = goodbye\n";
>
> public static void main ( String args[] )
> {
> PythonInterpreter interp = new PythonInterpreter();
> interp.exec(my_class_source);
> interp.exec(create_instance);
> interp.exec(invoke_hello);
> interp.exec(overwrite_meth);
> interp.exec(invoke_hello);
> }
>
> }
> //************************************************************
> end SelfMod.java ---------------------------------------------
>
> need-to-complete-my-coursework-for-telepathy-101-ly y'rs
>
More information about the Python-list
mailing list