Re: Best way to pickle functions

2009-04-05 Thread azrael
As in Python everythong is an object you could use __name__. >>> import cPickle >>> def def1(): ...pass >>> def def2(): ...pass >>> def1.__name__ def1 >>> def2.__name__ def2 in this case you can combine __name__ to get the object name and then combine it with eval to pickle. >>> pickleSt

Re: Best way to pickle functions

2009-04-03 Thread Aaron Brady
On Apr 3, 3:48 pm, Aaron Scott wrote: > > Why not use import ?  Simply recreate the source file, if necessary, and > > import it again. > > Ah, you'd think it would be that easy :P > > The problem with just importing a module is that the module is then > cached in memory. Multiple copies of the pr

Re: Best way to pickle functions

2009-04-03 Thread Aaron Scott
> Why not use import ?  Simply recreate the source file, if necessary, and > import it again. > Ah, you'd think it would be that easy :P The problem with just importing a module is that the module is then cached in memory. Multiple copies of the program are running on a server, and each of them h

Re: Re: Best way to pickle functions

2009-04-03 Thread Dave Angel
Aaron Scott wrote: Pickling the source code is much sturdier. It's very unlikely that the same code runs differently in different interpreters. It's much more likely that the same code runs the same, or not at all. Okay, I've run into another problem. I've saved the code to a string, so

Re: Best way to pickle functions

2009-04-03 Thread Aaron Scott
Never mind. Solved the problem by putting the functions in a class and dumping that into a string. Then, when I need it, I executed the string to get myself the class, then created an instance of that class which gave me access to those functions along with the correct scope. Probably not the smart

Re: Best way to pickle functions

2009-04-03 Thread Aaron Scott
> Pickling the source code is much sturdier.  It's very unlikely that > the same code runs differently in different interpreters.  It's much > more likely that the same code runs the same, or not at all. Okay, I've run into another problem. I've saved the code to a string, so I can call it up when

Re: Best way to pickle functions

2009-04-03 Thread Aaron Brady
On Apr 3, 11:04 am, Aaron Scott wrote: > I have a number of functions that I need to pickle without necessarily > knowing their names in advance. My first thought was to put all the > functions in a class, then pickle the class, but it doesn't really > work like I expected it to. > >         impor