Executing binaries...?

M.-A. Lemburg mal at lemburg.com
Sat Oct 16 07:30:45 EDT 1999


"Magnus L. Hetland" wrote:
> 
> Is there any way to execute python binaries with something like
> execfile (giving it a special environment as a dict)? The only way I
> can thing of is using execfile that imports another file (which is
> compiled)... Is there any other way?

def execpyc(filename,globals=None,locals=None):

    """ Execute a byte compiled file filename in globals, locals 
    """
    import marshal
    f = open(filename,'rb')
    f.read(8) # skip header (id check omitted)
    code = marshal.load(f)
    exec code in globals,locals
 

-- 
Marc-Andre Lemburg
______________________________________________________________________
Y2000:                                                    76 days left
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/






More information about the Python-list mailing list