发布时间:2019-09-22 07:54:50编辑:auto阅读(2204)
装饰器:
def auth(func):
def wrapper(name): 如果函数带参数,要加在这里
user=raw_input("input passwd:").strip()
if user=='test':
print "welcome login"
func(name) 如果函数带参数,要加在这里
else:
print "auth is denied"
return wrapper
@auth
def task(name): 带参数的函数
print "do something"
task(name)
异常处理:
try:
name="kim"
name_list=['kim','deng','min']
print Name
# print name_list[4]
except NameError,err:
print err
print '--do sth else--'
except Exception,e: 可以抓住所有的异常
print ''
else: 没有抓住异常则else
print ''
finally: 无论有没有异常都会执行
print ''
手动触发异常:
class myException(Exception):
pass
try:
code
raise myException
except ......
上一篇: python3.4 之sqlite3,
下一篇: assign之python文本处理
51112
50503
41117
37965
32433
29333
28205
23050
23016
21339
1376°
2074°
1726°
1655°
1943°
1728°
2399°
4052°
3936°
2807°