IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    将PyCodeObject保存为pyc

    sky发表于 2016-03-31 13:29:45
    love 0
    #!/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)
    


沪ICP备19023445号-2号
友情链接