exporting imports to reduce exe size?

Steve Holden steve at holdenweb.com
Tue Apr 12 15:18:13 EDT 2005


Ron_Adam wrote:
> In looking at ways to reduce the size of exe's created with py2exe,
> I've noticed that it will include a whole library or module even if I
> only need one function or value from it.  
> 
> What I would like to do is to import individual functions and then
> export 'write' them to a common resource file and import that with
> just the resources I need in them.
> 
You've been thinking again, Ron ...

> Has anyone tried this?  
> 
I'd be surprised if they had (see below).

> I'm considering using pickle to do it, but was wondering if this is
> even a viable idea?  
> 
What would you pickle and what not? The reason that a function is stored 
in a module is often because the module contains other supporting code 
that it needs. Generally the elements of a module should have a 
higher-than-random degree of interdependence.

> Is it possible to pickle the name space after the imports and then
> reload the name space in place of the imports later?
> 
This would be quite a feat of introspection if you could do it.

> Cheers, 
> Ron
> 

As another respondent suggested the savings of this technique would 
likely not be a reasonable return on  the development and support effort.

regards
  Steve
-- 
Steve Holden        +1 703 861 4237  +1 800 494 3119
Holden Web LLC             http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/




More information about the Python-list mailing list