推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
erevus
V2EX  ›  Python

如果使用 imp.load_source()加载文件,怎么把__init__文件也加载上.

  •  
  •   erevus · Jun 1, 2016 · 4383 views
    This topic created in 3771 days ago, the information mentioned may be changed or developed.
    接口会传我一个 py 文件的绝对路径,我需要动态加载这些 python 文件.因为 init 上写了这些 py 的 import,所以需要运行 init 文件
    2 replies  •  2016-06-02 11:30:01 +08:00
    julyclyde
        1
    julyclyde  
       Jun 1, 2016
    为什么所以?
    erevus
        2
    erevus  
    OP
       Jun 2, 2016
    已经解决

    a = imp.load_source('main', '/xxxx.py')
    b = a.main
    a.main.func_globals.update(globals())
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3302 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 10:35 · PVG 18:35 · LAX 03:35 · JFK 06:35
    ♥ Do have faith in what you're doing.