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

Python中的raise语句

  •  
  •   hhrmatata · Apr 8, 2013 · 7793 views
    This topic created in 4917 days ago, the information mentioned may be changed or developed.
    raise语句不是作为引起异常的吗?
    web.py的cookbook中的这个rasie语句是什么用法呢?

        class SomePage:
            def POST(self):
                # Do some application logic here, and then:
                raise web.seeother('/someotherpage')
    6 replies  •  1970-01-01 08:00:00 +08:00
    binux
        1
    binux  
       Apr 8, 2013
    一个函数的返回除了return就是raise了
    如果不想return状态太多,借用一下很正常
    顺带,tornado是修改类状态
    paloalto
        2
    paloalto  
       Apr 8, 2013
    跳转 303还是301来着?记不清了。
    paloalto
        3
    paloalto  
       Apr 8, 2013   ❤️ 1
    以前遇到过一个类似的问题:
    “web.py的raise web.seeother()”:
    http://www.douban.com/note/259251417/
    dreampuf
        4
    dreampuf  
       Apr 9, 2013   ❤️ 1
    return, continue, break, yield, raise 本质都是为流程控制服务,你可以在WSGI函数里找到这种异常流程的处理。
    hhrmatata
        5
    hhrmatata  
    OP
       Apr 9, 2013
    我就先这么理解吧:web.seeother('/someotherpage')返回了一个303异常。
    Zhongwei
        6
    Zhongwei  
       Apr 9, 2013   ❤️ 1
    看一下 https://github.com/webpy/webpy/blob/master/web/webapi.py 里 seeother 的实现就一目了然了。seeother 继承自 class Redirect(HTTPError)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2671 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 14:33 · PVG 22:33 · LAX 07:33 · JFK 10:33
    ♥ Do have faith in what you're doing.