啄木鸟,python讲座,源码_part2

啄木鸟,python讲座,源码_part2

---------------------------------------


#******** some class egs. ***********


# eg1.
class c1:
      def __init__(self):
          self.message = 'init'

t1 = c1()
print "t1.message = ", t1.message

def __init__(self,message):
    self.message = message

c1.__init__ = __init__
t2 = c1('hello')
print t2.message

# eg2.
class c2(c1):
      def __del__(self):
          print 'del c2 instance', self.message

def a():
    ls = c2('hello')

a()

# eg3.
class c3:
      def __call__(self):
          print self.message

t4 = c1('hello')
c1.__bases__ += (c3,)
t4()

# eg4.
class c4:
      def __call__(self):
          self.__class__ = c5
          print 'c4'

class c5:
      def __call__(self):
          self.__class__ = c4
          print 'c5'

t4 = c4()
t4()

#

if __name__ == '__main__':
   print __name__

#
print "__builtins__ = ", __builtins__



















你可能感兴趣的:(啄木鸟,python讲座,源码_part2)