推荐学习书目
› 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 · 7927 views
    This topic created in 4959 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
    binux
    Apr 8, 2013
    1
    一个函数的返回除了return就是raise了
    如果不想return状态太多,借用一下很正常
    顺带,tornado是修改类状态
    paloalto
    paloalto
    Apr 8, 2013
    2
    跳转 303还是301来着?记不清了。
    paloalto
    paloalto
    Apr 8, 2013❤️1
    3
    以前遇到过一个类似的问题:
    “web.py的raise web.seeother()”:
    http://www.douban.com/note/259251417/
    dreampuf
    dreampuf
    Apr 9, 2013❤️1
    4
    return, continue, break, yield, raise 本质都是为流程控制服务,你可以在WSGI函数里找到这种异常流程的处理。
    hhrmatata
    hhrmatata
    OP
    Apr 9, 2013
    5
    我就先这么理解吧:web.seeother('/someotherpage')返回了一个303异常。
    Zhongwei
    Zhongwei
    Apr 9, 2013❤️1
    6
    看一下 https://github.com/webpy/webpy/blob/master/web/webapi.py 里 seeother 的实现就一目了然了。seeother 继承自 class Redirect(HTTPError)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4944 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 07:07 · PVG 15:07 · LAX 23:07 · JFK 02:07
    ♥ Do have faith in what you're doing.