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

一起来探讨 Python 中认 object 作父的类的优缺点吧

  •  
  •   northisland · 2015-11-02 11:49:16 +08:00 · 2147 次点击
    这是一个创建于 3091 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我 Python 学的不系统,也不拿 Python 做大项目,所以水平不高
    就当我在这里抛砖引玉了


    http://stackoverflow.com/questions/9698614/super-raises-typeerror-must-be-type-not-classobj-for-new-style-class
    http://stackoverflow.com/questions/9699591/instance-is-an-object-but-class-is-not-a-subclass-of-object-how-is-this-po/9699961#9699961
    两个问题所说

    old-style class
    isinstance( New_Class, type ) == False

    new-style class
    isinstance( New_Class, type ) == True

    而实现 new-style class 的简单方法就是:
    使用 object 作父类,新建 class

    然后, new-style class 能使用 super()继承函数等用法。

    我知道的就这么多,求指教

    4 条回复    2015-11-02 16:44:43 +08:00
    neoblackcap
        1
    neoblackcap  
       2015-11-02 11:52:14 +08:00   ❤️ 1
    还有 Python 3 根本没有旧式类
    repus911
        2
    repus911  
       2015-11-02 13:22:12 +08:00   ❤️ 1
    肯定是用新式类啊
    janxin
        3
    janxin  
       2015-11-02 13:42:51 +08:00   ❤️ 1
    多继承属性查找机制不同
    repus911
        4
    repus911  
       2015-11-02 16:44:43 +08:00   ❤️ 1
    @property 只支持新式类
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2686 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 15:10 · PVG 23:10 · LAX 08:10 · JFK 11:10
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.