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

python 有没有办法,可以在代码中将一段字符串 load 进来作为代码的一部分执行

  •  
  •   996635 · Dec 22, 2016 · 3303 views
    This topic created in 3569 days ago, the information mentioned may be changed or developed.
    不是 eval,需要包含 context
    8 replies  •  2016-12-22 21:14:30 +08:00
    keenkiller
        1
    keenkiller  
       Dec 22, 2016
    没看懂 如果是 python 代码,可以用`importlib`之类的方法动态加载吧。。
    xFrank
        2
    xFrank  
       Dec 22, 2016
    试试 pickle
    996635
        3
    996635  
    OP
       Dec 22, 2016
    @tairan2006 importlib 我试用一下给你反馈, 我的需求就是 http server 接受提交的 code,然后执行后返回结果

    @xFrank 这个是序列化工具吧? 并不能序列化代码
    v3exad
        4
    v3exad  
       Dec 22, 2016
    exec ...
    yongzhong
        5
    yongzhong  
       Dec 22, 2016
    exec
    phrack
        6
    phrack  
       Dec 22, 2016 via Android
    为什么不 Google?
    Kilerd
        7
    Kilerd  
       Dec 22, 2016
    保存到文件, 然后 再 ·python file.py· 就好啦。
    akira
        8
    akira  
       Dec 22, 2016
    pypy?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1392 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 16:30 · PVG 00:30 · LAX 09:30 · JFK 12:30
    ♥ Do have faith in what you're doing.