modifying source at runtime - jython case
Hello folks 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. Thanks for response, Jan -- http://mail.python.org/mailman/listinfo/python-list
Re: modifying source at runtime - jython case
In article <[EMAIL PROTECTED]>, 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 > -- http://mail.python.org/mailman/listinfo/python-list
Re: modifying source at runtime - jython case
In article <[EMAIL PROTECTED]>, Kent Johnson wrote: > Jan Gregor wrote: >> Hello folks >> >> 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. > > Can you be more specific? Python and Jython allow classes to be modified at > runtime without changing the source code or compiling new code. For example > you can add and remove methods and attributes from a class and change the > base classes of a class. You can also modify individual instances of a class > to change their attributes and behaviour independently of other instances of > the class. What are you trying to do? For example see > http://groups.google.com/group/comp.lang.python/browse_frm/thread/8f7d87975eab0ca4/18215f7ce8f5d609?rnum=15#18215f7ce8f5d609 > http://groups.google.com/group/comp.lang.python/browse_frm/thread/a0b19b37ac48deaa/e599041de4b8feb0?rnum=22#e599041de4b8feb0 > > Kent thanks for links, I'll look at them. Alan showed me some possibilities, i'm not quite sure how to initiate modification and the way import keyword works in case of modified imported modules. 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. so task is to reload class defitions (from source files) and modify also existing instances (their methods). Jan -- http://mail.python.org/mailman/listinfo/python-list
Re: modifying source at runtime - jython case
Kent Johnson wrote: > Jan Gregor wrote: > >> 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. >> so task is to reload class defitions (from source files) and modify also >> existing instances (their methods). > > > Ok, I think my first reply completely missed the mark. IIUC what you > want is hard. This recipe might help: > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/160164 > > Kent Yes, this is right way. And it's working. Thanks, Jan -- http://mail.python.org/mailman/listinfo/python-list
Re: redirect of standard output of jython to JTextArea
problem solved. in class: sys.stdout = StdOutRedirector(self) class StdOutRedirector: def __init__(self, console): self.console = console def write(self, data): #print >> sys.stderr, ">>%s<<" % data if data != '\n': # This is a sucky hack. Fix printResult self.console.textArea.append(data) Jan Jan Gregor wrote: Hello I want to redirect output of jython's functions print and println to JTextArea component. Is it possible ? I tried this (swingConsole.textArea is instance): In my class self.printStream= MyPrintStream(System.out) System.setOut(self.printStream) class MyPrintStream (PrintStream): def println (str): swingConsole.textArea.append(str) def print (str): swingConsole.textArea.append(str) Output is still directed to standard output. Thanks for help, Jan -- http://mail.python.org/mailman/listinfo/python-list
redirect of standard output of jython to JTextArea
Hello I want to redirect output of jython's functions print and println to JTextArea component. Is it possible ? I tried this (swingConsole.textArea is instance): In my class self.printStream= MyPrintStream(System.out) System.setOut(self.printStream) class MyPrintStream (PrintStream): def println (str): swingConsole.textArea.append(str) def print (str): swingConsole.textArea.append(str) Output is still directed to standard output. Thanks for help, Jan -- http://mail.python.org/mailman/listinfo/python-list
python script under windows
Hello I run python script on another computer and want to "survive" that script after my logout. the script also uses drive mapping to network drive. Can you help me ? Or better is there some info for unix person how to survive with python on windows ;-) thanks, jan gregor -- http://mail.python.org/mailman/listinfo/python-list
Re: jython and concatenation of strings
Ok, thanks. I didn't think that += operator is nondestructive operation - but strings are immutable so this makes sense. On 2004-12-13, Diez B. Roggisch <[EMAIL PROTECTED]> wrote: >> I found that price of += operator on string is too high in jython. For >> example 5000 such operations took 90 seconds (i generated html copy of >> table with 1000 rows and 5 columns). Generation of row data into separate >> string and joining after lead to time 13 seconds !!! > > Its generally not recommended to use simple string concatenation for > building larger strings - neither in python nor in java/jython. > > afaik there are two solutions to this: The java-way and the jython way: > > java: Use StringBuffer > python: use a list, and append the strings to that. Then, when you want the > result, do > > "".join(stringlist) > -- http://mail.python.org/mailman/listinfo/python-list
jython and concatenation of strings
Hello I found that price of += operator on string is too high in jython. For example 5000 such operations took 90 seconds (i generated html copy of table with 1000 rows and 5 columns). Generation of row data into separate string and joining after lead to time 13 seconds !!! What's alternative way to do that ? (similiar parts of my code are terribbly slow and such simple solution as above didn't help). Thanks, Jan -- http://mail.python.org/mailman/listinfo/python-list
Re: jython and concatenation of strings
StringBuffer class from java was right solution - yours looses encoding, and in jython I was unable to get it back - in python it worked fine. Jan > I don't use Jython, but are you not able to do something like: > > string_list = [] > for ... in ...: > ... > string_list.append(...) > ... > string = ''.join(string_list) > > This is the usual Python idiom and is usually faster than the += idiom. > > Note too that +ing strings in Java also has this problem -- hence > StringBuffer or whatever it's called. > > Steve -- http://mail.python.org/mailman/listinfo/python-list
installation of jython program
Hello, I've done database console in jython called jydbconsole. It's now available on sourceforge. As you can guess console needs jdbc drivers. The script that runs jython itself doesn't public -cp option to add another classpaths. Yes I need to add jdbc drivers to classpath ... Of course I see solution to modify the jython script and distribute it with my program but is there cleaner solution ? Thanks, Jan -- http://mail.python.org/mailman/listinfo/python-list