Best way to pickle functions

Aaron Brady castironpi at gmail.com
Sat Apr 4 05:32:26 CEST 2009


On Apr 3, 3:48 pm, Aaron Scott <aaron.hildebra... at gmail.com> 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 program are running on a
> server, and each of them have something akin to a "randomfunctions"
> module. When the first program is accessed, it loads
> "randomfunctions". When the second program is accessed, it uses the
> "randomfunctions" module already in memory, even though it doesn't
> contain the right functions. So, I have to pull in these functions
> dynamically.

Here I found this cookie you can have it. </cookie>

imp.load_source(name, pathname[, file])
Load and initialize a module implemented as a Python source file and
return its module object. If the module was already initialized, it
will be initialized again.

'again' was actually in italics in the docs.  </much rejoicing>

I presume you're aware of eval and exec.



More information about the Python-list mailing list