推荐学习书目
› 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
guanganqishi
V2EX  ›  Python

Python 内置函数 compile 用法

  •  
  •   guanganqishi · Feb 3, 2018 · 5020 views
    This topic created in 3158 days ago, the information mentioned may be changed or developed.
    现在有一个文件 xx.py 里有个代码 print('hello python'),在 test.py 中怎么用内置函数 compile 执行它
    3 replies  •  2018-02-05 16:50:10 +08:00
    KKKKKK
        1
    KKKKKK  
       Feb 3, 2018 via Android
    Eval(open(xx.py).Read())
    fakepoet
        2
    fakepoet  
       Feb 4, 2018
    with open('xx.py', 'r') as f:
    obj = compile(f.read(), '', 'exec')
    exec(obj)
    Ctry
        3
    Ctry  
       Feb 5, 2018
    import xx


    e = compile('', 'xx.py', 'exec')
    exec(e)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3018 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 11:17 · PVG 19:17 · LAX 04:17 · JFK 07:17
    ♥ Do have faith in what you're doing.