V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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
cevincheung
V2EX  ›  Python

玩了一下午的 tornado,提几个问题

  •  
  •   cevincheung ·
    cevin · Feb 2, 2015 · 3196 views
    This topic created in 4102 days ago, the information mentioned may be changed or developed.
    """
    自定义错误页面
    """
    class errorController(userController):
        def get(self):
            self.write('404 not found');
        def post(self):
            errorController.get(self);
    

    怎么实现类型这样的效果:

    """
    自定义错误页面
    """
    class errorController(userController):
        def get(self):
        def post(self):
        def delete(self):
        # options put ......
            self.write('404 not found/ method not allowed');
    

    然后是关于class继承

    class a():
        def __init__():
            pass;
    
    class b(a):
        def __init__():
            pass;
    

    像php有parant::__init()__可以执行继承的class的同名方法。python捏?
    还有就是像

    class baseController(tornado.web.RequestHandler):
    class userController(baseController):
    class panelController(userController):
    # 然后就莫名其妙500了……
    

    然后是怎么动态加载一些python文件,比如:

    a = 'a';
    import a;
    # 但是即便实现了好像也没用,python貌似所有执行过程中需要的文件都需要预先import……
    # 像php   if($get[a]) include_once $get[a].php
    

    暂时这么多……

    5 replies    2015-02-03 10:11:07 +08:00
    dddd
        1
    dddd  
       Feb 2, 2015   ❤️ 1
    基础比我还差还是先放下 tornado 吧……
    14
        2
    14  
       Feb 2, 2015
    class b(a):
    ....def __init__(self):
    ........super(b).__init__(self)

    a = __import__('a')
    yetone
        3
    yetone  
       Feb 2, 2015
    zhwei
        4
    zhwei  
       Feb 3, 2015
    1、

    ```python

    class errorController(userController):
    def get(self):
    self.write('404 not found') # 没有分号

    post = delete = get

    ```

    2、楼上正解 `super()`
    3、[importlib](https://docs.python.org/3/library/importlib.html)


    PS. 这些跟Tornado没什么关系, 都是Python基础语法,初学Python并且想做web的话可以用些更轻量的框架。
    zenliver
        5
    zenliver  
       Feb 3, 2015
    你还是先把基础搞好吧,,,
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5029 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 60ms · UTC 01:09 · PVG 09:09 · LAX 18:09 · JFK 21:09
    ♥ Do have faith in what you're doing.