In [4]:
def test():
test = 10
return test
print test()
print test()
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()
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="")
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)
In [3]:
In [ ]: