Re: How to do a controlled exec compiled and dynamic-load files?

Steven D. Majewski (sdm7g@virginia.edu)
Wed, 25 Jan 1995 15:52:27 -0500 (EST)

On Wed, 25 Jan 1995, Ken Manheimer wrote:

> I need to be able to control loads of compiled and dynamic-load (as
> well as normal source) files, in order to implement an extension to
> the python import statement. Is there a way to do so that i'm
> missing?
>
> In particular, i need to load the files with respect to specific
> environment bindings, which i do not seem to be able to control using
> the new 'imp' module's '.load_compiled()' and '.load_dynamic()'. Is
> there any way from within python to read in a compiled or dynamic-load
> file and execute it, wrt a particular binding environment?

For "normal source" (.py) & .pyc files you can use __builtin__.execfile
execfile( pathname, global_dict, local_dict )
[ And I expect now, optionally a builtin_dict, although I haven't tried
it yet. This (execfile) is not documented in the hypertext docs (I think);
I haven't printed out the 1.2 beta docs yet - is it in there ? ]

- or just read in the string ( text or byte-code ) and 'exec' it with
the dictionary that provides the proper context.

BUT: for compiled dynamic-loadable modules ? Hmmm...
I don't think there is a general mechanism. The compiled module
would probably require some hooks to allow this. This will take
some thought!

Can you give me a specific example or scenario ?

---| Steven D. Majewski (804-982-0831) <sdm7g@Virginia.EDU> |---
---| Computer Systems Engineer University of Virginia |---
---| Department of Molecular Physiology and Biological Physics |---
---| Box 449 Health Science Center Charlottesville,VA 22908 |---