推荐学习书目
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 · 2493 views
    This topic created in 2721 days ago, the information mentioned may be changed or developed.

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

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

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

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