In [4]:
def test():
    test = 10
    return test

print test()
print test()


10
10

In [27]:
class A(object):
    def __init__(self):
        print("A.__init__")
        self.foo()
    
    def foo(self):
        print("A.foo()")
        
class B(A):
    def __init__(self):
        print("B.__init__")
        super(B, self).__init__()
        
class C(B):
    def __init__(self):
        print("C.__init__")
        super(C, self).__init__()
        
    def foo(self):
        print("C.foo()")
        
a = A()
print("---")
b = B()
print("---")
c = C()


A.__init__
A.foo()
---
B.__init__
A.__init__
A.foo()
---
C.__init__
B.__init__
A.__init__
C.foo()

In [29]:
from __future__ import print_function

class A(object):
    def __init__(self):
        self.foo()
    
    def foo(self):
        print("A.foo()")
        
class B(object):
    def __init__(self):
        print('B.__init__')
        
    def bar(self):
        print("B.bar()")
        
class C(A,B):
#    def __init__(self):
#        super(C, self).__init__()
        
    def foo(self):
        print("C.foo()")
        
a = A()
print("-----------")
b = B()
print("-----------")
c = C()
c.bar()
print("isinstance(c, A)=", isinstance(c, A), "\n",
      "isinstance(c, B)=", isinstance(c, B), "\n",
      "isinstance(c, C)=", isinstance(c, C), "\n",
      "isinstance(b, C)=", isinstance(b, C), sep="")


A.foo()
-----------
B.__init__
-----------
C.foo()
B.bar()
isinstance(c, A)=True
isinstance(c, B)=True
isinstance(c, C)=True
isinstance(b, C)=False

In [5]:
class Blah(object):
    a = 1

blah = Blah()
print(blah.a)

def args(**kwargs):
    for key, value in kwargs.iteritems():
        blah.__setattr__(key, value)

args(a=5)
print(blah.a)


1
5

In [3]:



Object `blah` not found.

In [ ]: