#!/usr/bin/env python
import py_compile
import imp
import os
def pycodeobject2pyc(pyobj, pycfile):
with open(pycfile, 'wb') as fc:
fc.write('\0\0\0\0')
timestamp = long(os.fstat(fc.fileno()).st_mtime)
py_compile.wr_long(fc, timestamp)
marshal.dump(pyobj, fc)
fc.flush()
fc.seek(0, 0)
MAGIC = imp.get_magic()
fc.write(MAGIC)