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

Python中的raise语句

  •  
  •   hhrmatata · 2013-04-08 23:36:23 +08:00 · 6706 次点击
    这是一个创建于 4034 天前的主题,其中的信息可能已经有所发展或是发生改变。
    raise语句不是作为引起异常的吗?
    web.py的cookbook中的这个rasie语句是什么用法呢?

        class SomePage:
            def POST(self):
                # Do some application logic here, and then:
                raise web.seeother('/someotherpage')
    6 条回复    1970-01-01 08:00:00 +08:00
    binux
        1
    binux  
       2013-04-08 23:40:46 +08:00
    一个函数的返回除了return就是raise了
    如果不想return状态太多,借用一下很正常
    顺带,tornado是修改类状态
    paloalto
        2
    paloalto  
       2013-04-08 23:41:13 +08:00
    跳转 303还是301来着?记不清了。
    paloalto
        3
    paloalto  
       2013-04-08 23:45:33 +08:00   ❤️ 1
    以前遇到过一个类似的问题:
    “web.py的raise web.seeother()”:
    http://www.douban.com/note/259251417/
    dreampuf
        4
    dreampuf  
       2013-04-09 01:23:34 +08:00   ❤️ 1
    return, continue, break, yield, raise 本质都是为流程控制服务,你可以在WSGI函数里找到这种异常流程的处理。
    hhrmatata
        5
    hhrmatata  
    OP
       2013-04-09 10:10:24 +08:00
    我就先这么理解吧:web.seeother('/someotherpage')返回了一个303异常。
    Zhongwei
        6
    Zhongwei  
       2013-04-09 11:00:45 +08:00   ❤️ 1
    看一下 https://github.com/webpy/webpy/blob/master/web/webapi.py 里 seeother 的实现就一目了然了。seeother 继承自 class Redirect(HTTPError)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3487 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 11:14 · PVG 19:14 · LAX 04:14 · JFK 07:14
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.