摘要:
An simple example presentation 1 #inherit 2 class Parent: 3 '''reprensent parent''' 4 def __init__(self, name, age): 5 self.name = name 6 self.age = age 7 print'initialized parent:{}'.format(self.name) 8 def show(self): 9 print 'name:{0},age:{1}'.format(se... 阅读全文
摘要:
An example presentation 1 import sys 2 class test: 3 def __enter__(self): 4 print("enter") 5 return 1 # return value is assigned to 't' 6 def __exit__(self,*args): 7 print("exit") 8 #return True # True: raise statement is never executed, thinking n... 阅读全文
摘要:
1. raise an exception defined by user. 1 class MyException(Exception): 2 ''' An exception defined by user,inherit from Top Exception''' 3 def __init__(self,length,atleastlength): 4 Exception.__init__(self)#invoking parent __init__() method manually 5 self.length = length 6 .. 阅读全文