[ create a new paste ] login | about

Link: http://codepad.org/XCVdKCPm    [ raw code | output | fork ]

pentie - Python, pasted on Nov 22:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# -*- coding: utf-8 -*-
class A(object):
    def __init__(self, arg1):
        print "init func in A, with arg1 '%s'" % arg1


class B(object):
    def __init__(self, arg1, arg2):
        print "init func in B, with arg1'%s', arg2 '%s'" % (arg1, arg2)

class C(A, B):
    def __init__(self, arg1, arg2):
        print "init func in C, with arg1'%s', arg2 '%s'" % (arg1, arg2)
        super(C, self).__init__(arg1) #这两行
        #A.__init__(self, arg1)       #等价
        B.__init__(self, arg1, arg2)
        print C.__mro__

c = C("C's arg1", "C's arg2")


Output:
1
2
3
4
init func in C, with arg1'C's arg1', arg2 'C's arg2'
init func in A, with arg1 'C's arg1'
init func in B, with arg1'C's arg1', arg2 'C's arg2'
(<class '__main__.C'>, <class '__main__.A'>, <class '__main__.B'>, <type 'object'>)


Create a new paste based on this one


Comments: