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

大家觉得 Python 的 exec 怎么样,能否常态化地用来执行或者在工程中大量使用

  •  
  •   lwxiang ·
    Lwxiang · Dec 22, 2015 · 3104 views
    This topic created in 3932 days ago, the information mentioned may be changed or developed.

    觉得在一些特定的场合下,把代码块封存起来用 exec 去执行,可以比较显式地管理

    然后看到了这个:
    http://lucumr.pocoo.org/2011/2/1/exec-in-python/

    然后因为实习的时候有个统一管理所有 check 函数的需求,所以想到了把所有函数放进数据库里,用 exec 调用执行,这样增减变更的时候就不用重启 server 惹;虽然方案最后没有被采用,但是还是撸了一个小工具出来,当作学习吧

    git:https://github.com/Lwxiang/fangzi

    最后想请问一下大家目前 exec 除了一些模板渲染还有哪些比较多的用处呢

    lwxiang
        1
    lwxiang  
    OP
       Dec 22, 2015
    另外 exec 在某些情况下效率比一般的快(因为在 local 里),所以对于使用频率很高的代码块应该还不错?:)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   5230 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 18ms · UTC 01:52 · PVG 09:52 · LAX 18:52 · JFK 21:52
    ♥ Do have faith in what you're doing.