上传文件至「week12」
This commit is contained in:
22
week12/ex5.py
Normal file
22
week12/ex5.py
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
from continueanyway import ca
|
||||||
|
|
||||||
|
def handleKBI(lmbd):
|
||||||
|
def runlambda(*args,**kwargs):
|
||||||
|
try:
|
||||||
|
return lmbd(*args,**kwargs)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("\nKeyboardInterrupt detected!")
|
||||||
|
return runlambda
|
||||||
|
|
||||||
|
@handleKBI
|
||||||
|
def inputIE(*args,**kwargs):
|
||||||
|
return input(*args,**kwargs)
|
||||||
|
|
||||||
|
def main():
|
||||||
|
l1 = inputIE("pls input sth")
|
||||||
|
print(l1)
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
21
week12/ex6.py
Normal file
21
week12/ex6.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
from continueanyway import ca
|
||||||
|
|
||||||
|
def handleArithmeticError(lmbd):
|
||||||
|
def runlambda(*args,**kwargs):
|
||||||
|
try:
|
||||||
|
return lmbd(*args,**kwargs)
|
||||||
|
except ArithmeticError:
|
||||||
|
print("ArithmeticError detected!")
|
||||||
|
return runlambda
|
||||||
|
|
||||||
|
@handleArithmeticError
|
||||||
|
def div(a,b):
|
||||||
|
return a/b
|
||||||
|
|
||||||
|
def main():
|
||||||
|
print(div(1,0))
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
34
week12/ex7.py
Normal file
34
week12/ex7.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
from continueanyway import ca
|
||||||
|
|
||||||
|
def handleAttrError(lmbd):
|
||||||
|
def NoneR(*args,**kwargs):
|
||||||
|
return None
|
||||||
|
def runlambda(*args,**kwargs):
|
||||||
|
try:
|
||||||
|
return lmbd(*args,**kwargs)
|
||||||
|
except AttributeError:
|
||||||
|
print("AttributeError detected!")
|
||||||
|
return NoneR
|
||||||
|
return runlambda
|
||||||
|
|
||||||
|
class listIE(list):
|
||||||
|
def __init__(self, iterable):
|
||||||
|
super().__init__(iterable)
|
||||||
|
|
||||||
|
@handleAttrError
|
||||||
|
def __getattribute__(self, name):
|
||||||
|
return super().__getattribute__(name)
|
||||||
|
|
||||||
|
@handleAttrError
|
||||||
|
def __call__(self, *args, **kwds):
|
||||||
|
return super().__call__(*args, **kwds)
|
||||||
|
|
||||||
|
def main():
|
||||||
|
l1 = listIE([1,2,3])
|
||||||
|
print(l1.popp(1))
|
||||||
|
print(l1.pop(1))
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user