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

断点调试装饰器遇到的疑问疑问🤔️

  •  
  •   Litecoins · Jan 19, 2019 · 2779 views
    This topic created in 2861 days ago, the information mentioned may be changed or developed.

    向大家请教一个问题哈,我在第 11 行设置了断点,为什么程序还是运行了 11 行之后的代码呢?

    8 replies  •  2019-01-20 09:58:15 +08:00
    xpresslink
    xpresslink
    Jan 19, 2019
    1
    因为装饰器是在编译字节码的阶段就执行生成了,说白了装饰器只是语法糖。
    megachweng
    megachweng
    Jan 19, 2019 via iPhone
    2
    function decorators are executed as soon as the module is imported, but the decorated functions only run when they are explicitly invoked
    lance6716
    lance6716
    Jan 20, 2019 via Android
    3
    Python 这种轻松的语言竟然还有调试器…断点打在这里不能理解是想在什么时候停止,应该打在 12 行吧
    GeruzoniAnsasu
    GeruzoniAnsasu
    Jan 20, 2019
    4
    @xpresslink 是语法糖,但装饰器相当于一个赋值语句,在执行流中的位置还是比较明确的

    @register 相当于 f1 = register(f1),执行到这行时,在装饰器函数内部下断应该是可以断下来的

    在 12 行下断只有在执行 f1()时才会中断
    Litecoins
    Litecoins
    OP
    Jan 20, 2019
    5
    @xpresslink 明白了,谢谢!
    Litecoins
    Litecoins
    OP
    Jan 20, 2019
    6
    @megachweng 明白了,谢谢!
    Litecoins
    Litecoins
    OP
    Jan 20, 2019
    7
    @lance6716 明白了,感谢!
    Litecoins
    Litecoins
    OP
    Jan 20, 2019
    8
    @GeruzoniAnsasu 明白了,感谢!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2070 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 12:36 · PVG 20:36 · LAX 04:36 · JFK 07:36
    ♥ Do have faith in what you're doing.