V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2016-06-01 10:36:26 +08:00 · 3244 次点击
    这是一个创建于 2879 天前的主题,其中的信息可能已经有所发展或是发生改变。
    接口会传我一个 py 文件的绝对路径,我需要动态加载这些 python 文件.因为 init 上写了这些 py 的 import,所以需要运行 init 文件
    2 条回复    2016-06-02 11:30:01 +08:00
    julyclyde
        1
    julyclyde  
       2016-06-01 14:11:55 +08:00
    为什么所以?
    erevus
        2
    erevus  
    OP
       2016-06-02 11:30:01 +08:00
    已经解决

    a = imp.load_source('main', '/xxxx.py')
    b = a.main
    a.main.func_globals.update(globals())
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1552 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 16:54 · PVG 00:54 · LAX 09:54 · JFK 12:54
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.