class Base(object):     def __init__(self):

print 'Base create'

class childB(Base):

def __init__(self):

print 'creat B ',

super(childB, self).__init__()

class childA(childB,Base):

def __init__(self):

print 'creat A ',

Base.__init__(self)

if __name__=="__main__":

childA()

结果:creat A  Base create

class Base(object):

def __init__(self):

print 'Base create'

class childA(Base):

def __init__(self):

print 'creat A ',

Base.__init__(self)

class childB(childA,Base):

def __init__(self):

print 'creat B ',

super(childB, self).__init__()

if __name__=="__main__":

childB()

结果:creat B  creat A  Base create

class Base():

def __init__(self):

print 'Base create'

class childA(Base):

def __init__(self):

print 'creat A ',

Base.__init__(self)

if __name__=="__main__":
    childA()

结果:creat A  Base create

class Base():

def __init__(self):

print 'Base create'

class childA(Base):

def __init__(self):

print 'creat B ',

super(childA, self).__init__()

if __name__=="__main__":

childA()

结果:

creat B
Traceback (most recent call last):
  File "D:\eclipse\test\test1.py", line 17, in <module>
    childA()
  File "D:\eclipse\test\test1.py", line 14, in __init__
    super(childA, self).__init__()
TypeError: super() argument 1 must be type, not classobj

python类中super()和__init__()的区别的更多相关文章

  1. 【转】python类中super()和__init__()的区别

    [转]python类中super()和__init__()的区别 单继承时super()和__init__()实现的功能是类似的 class Base(object): def __init__(se ...

  2. Python类中super()和__init__()的关系

    Python类中super()和__init__()的关系 1.单继承时super()和__init__()实现的功能是类似的 class Base(object): def __init__(sel ...

  3. 【转】python---方法解析顺序MRO(Method Resolution Order)<以及解决类中super方法>

    [转]python---方法解析顺序MRO(Method Resolution Order)<以及解决类中super方法> MRO了解: 对于支持继承的编程语言来说,其方法(属性)可能定义 ...

  4. 第7.14节 Python类中的实例方法详析

    第7.14节 Python类中的实例方法详析 一.    实例方法的定义 在本章前面章节已经介绍了类的实例方法,实例方法的定义有三种方式: 1.    类体中定义实例方法 第一种方式很简单,就是在类体 ...

  5. 第8.6节 Python类中的__new__方法深入剖析:调用父类__new__方法参数的困惑

    上节<第8.5节 Python类中的__new__方法和构造方法__init__关系深入剖析:执行顺序及参数关系案例详解>通过案例详细分析了两个方法的执行顺序,不知大家是否注意到了,在上述 ...

  6. 孤荷凌寒自学python第二十四天python类中隐藏的私有方法探秘

    孤荷凌寒自学python第二十四天python类中隐藏的私有方法探秘 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 今天发现了python的类中隐藏着一些特殊的私有方法. 这些私有方法不管我 ...

  7. Python 简明教程 --- 20,Python 类中的属性与方法

    微信公众号:码农充电站pro 个人主页:https://codeshellme.github.io 与客户保持良好的关系可以使生产率加倍. -- Larry Bernstain 目录 类中的变量称为属 ...

  8. 第7.18节 案例详解:Python类中装饰器@staticmethod定义的静态方法

    第7.18节 案例详解:Python类中装饰器@staticmethod定义的静态方法 上节介绍了Python中类的静态方法,本节将结合案例详细说明相关内容. 一.    案例说明 本节定义了类Sta ...

  9. 第8.12节 Python类中使用__dict__定义实例变量和方法

    上节介绍了使用实例的__dict__查看实例的自定义属性,其实还可以直接使用__dict__定义实例变量和实例方法. 一. 使用__dict__定义实例变量 语法: 对象名. dict[属性名] = ...

随机推荐

  1. Excel取消超级链接

    背景 本人使用Excel作笔记,偶尔会将一些url存到文档中.Excel会自动给这些url加上超链接,下次使用的时候,因为会单机跳转,导致选中复制很不方便. 解决方式 修改配置,避免给自动url加上超 ...

  2. 分页sql优化

    如果分页sql里包含排序: select * from (...order by id) where rownum <=20 因为要排序,所以即使是分页只取20条,执行计划还是要把所有满足条件的 ...

  3. Android 上下文对象

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/40481055,本文出自:[张鸿洋的博客] 1.Context概念 其实一直想写一 ...

  4. Linux内核分析:打开文件描述符实现

    在Linux中每一个进程的数据是存储在一个task_struct结构(定义在sched.h中)中的. struct task_struct { volatile long state; /* -1 u ...

  5. linux 调用java main方法

    #!/bin/shexport LANG=zh_CNtimestamp=`date +%Y%m%d%H%M`/opt/java6/bin/java -Xms128m -Xmx512m -Dfile.e ...

  6. typedef 函数指针 数组 std::function

    1.整型指针 typedef int* PINT;或typedef int *PINT; 2.结构体 typedef struct { double data;}DATA,  *PDATA;  //D ...

  7. (转)解决Mac OS X上PhpStorm不能输入中文

    看到Netbeans上类似问题的解决办法: /Applications/netbeans/NetBeans 6.7.1/Content/Resource/netbeans/etc/netbeans.c ...

  8. JS汉语转拼音脚本

    测试代码: var anhui = "安徽"; //获得全拼 pinyin.getFullChars(anhui); //获得首拼 pinyin.getCamelChars(anh ...

  9. Oracle(控制用户权限)

    权限允许用户访问属于其它用户的对象或执行程序, ORACLE系统提供权限:Object 对象级.System 系统级 查看权限的数据字典: 字典名 含义 ROLE_SYS_PRIVS System p ...

  10. asp.net Forms身份验证

    Web.config中的配置<system.web><authentication mode="Forms"> <forms name="K ...