代码如下:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
class Tmp0(object):
def __init__(self):
print 'Tmp0 init'
def say0(self):
print 'Tmp0 say'
class Tmp1(object):
def __init__(self):
print 'Tmp1 init'
def say1(self):
print 'Tmp1 say'
def say0(self, tmp0):
self.tmp0 = tmp0
try:
tmp0.noExist()
except:
try:
tmp0.say0()
except:
raise
def tmp0Say(self):
self.tmp0.say0()
def main():
tmp0 = Tmp0()
tmp1 = Tmp1()
tmp1.say1()
tmp1.say0(tmp0)
tmp1.tmp0Say()
if __name__ == '__main__':
main()
运行结果如下:
Tmp0 init
Tmp1 init
Tmp1 say
Tmp0 say
Tmp0 say