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
Ultratude
V2EX  ›  Python

问一个 Python 3.4 closure 的问题

  •  
  •   Ultratude · 2015-06-20 14:15:02 +08:00 · 3611 次点击
    这是一个创建于 3227 天前的主题,其中的信息可能已经有所发展或是发生改变。
    有一项目 Python 2.7 的 code 类似这样,现在想要兼容 3.4。

    Python 3.4 下会报错,搜了很久没有很好的答案。
    求教,谢谢。
    7 条回复    2015-06-20 23:44:35 +08:00
    Ultratude
        1
    Ultratude  
    OP
       2015-06-20 14:20:01 +08:00
    主帖里贴两条 gist,会显示同一条两遍,貌似是 bug。
    所以错误贴在这里。
    https://gist.github.com/ultratude/29bb8021a3ac4f1153da
    Valyrian
        2
    Valyrian  
       2015-06-20 15:01:15 +08:00   ❤️ 1
    这。。感觉是应该能正常运行的code
    Ultratude
        3
    Ultratude  
    OP
       2015-06-20 15:14:00 +08:00
    @Valyrian 是啊,我也觉得没问题,十分蛋疼。
    kcworms
        4
    kcworms  
       2015-06-20 15:16:03 +08:00   ❤️ 1
    原因在 https://www.python.org/dev/peps/pep-3110/

    可以尝试:把异常实例里要用的内容拷贝一下,之后再也不要引用了
    killpanda
        5
    killpanda  
       2015-06-20 15:17:47 +08:00   ❤️ 1
    Ultratude
        6
    Ultratude  
    OP
       2015-06-20 15:42:56 +08:00
    @killpanda
    @kcworms
    非常感谢!
    isaaczeng
        7
    isaaczeng  
       2015-06-20 23:44:35 +08:00
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2690 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 12:31 · PVG 20:31 · LAX 05:31 · JFK 08:31
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.