V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · 2774 views
    This topic created in 3792 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   ·   Solana   ·   845 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 20:50 · PVG 04:50 · LAX 13:50 · JFK 16:50
    ♥ Do have faith in what you're doing.