Re: Editing a function in-memory and in-place

2006-04-28 Thread Ian Bicking
Thanks for the answers, very helpful. I think I'm going to give Peter's hack a try, as it's actually quite close to what I'm trying to do -- I get the source for the new function, then that lets me make the old function become the new one. But I'll probably also use Michael's solution for class

Re: Editing a function in-memory and in-place

2006-04-27 Thread bruno at modulix
Peter Otten wrote: (snip) Can you cheat and just assign another known good func_code object? def hello(): print hello ... def world(): print world ... def use_it(hello=hello, world=world): ... hello() ... world() ... use_it() hello world world.func_code = hello.func_code use_it()

Re: Editing a function in-memory and in-place

2006-04-27 Thread Michael Spencer
Ian Bicking wrote: I got a puzzler for y'all. I want to allow the editing of functions in-place. I won't go into the reason (it's for HTConsole -- http://blog.ianbicking.org/introducing-htconsole.html), except that I really want to edit it all in-process and in-memory. So I want the

Editing a function in-memory and in-place

2006-04-27 Thread Sori Schwimmer
Generate your function as a string. Be careful to indent correctly and append \n at line's end. Then execute the string with exec(name_of_string). Then edit your string as necessary, and execute again. An example follows, directly from one of my projects: # create a function to apply on

Editing a function in-memory and in-place

2006-04-26 Thread Ian Bicking
I got a puzzler for y'all. I want to allow the editing of functions in-place. I won't go into the reason (it's for HTConsole -- http://blog.ianbicking.org/introducing-htconsole.html), except that I really want to edit it all in-process and in-memory. So I want the identity of the function to

Re: Editing a function in-memory and in-place

2006-04-26 Thread Terry Reedy
Ian Bicking [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] The func_code attributes of functions is writable, but I don't know how to create the proper code object. Just compiling a new body isn't good enough. Did you directly compile the body or compile a function and then

Re: Editing a function in-memory and in-place

2006-04-26 Thread Peter Otten
Ian Bicking wrote: I got a puzzler for y'all. I want to allow the editing of functions in-place. I won't go into the reason (it's for HTConsole -- http://blog.ianbicking.org/introducing-htconsole.html), except that I really want to edit it all in-process and in-memory. So I want the