python 获取exception 名字

def func():
    list = []
    usr = input('username:')
    pwd = input('password:')
    try:
        list[4] # 这个是调用不了的,因为列表没有元素
    except Exception as e:
        print(e.__class__)
func()

username:11
password:1

def func():
    list = []
    usr = input('username:')
    pwd = input('password:')
    try:
        name # 这个变量是没法收到的
    except Exception as e:
        print(e.__class__)
func()

username:1
password:1

转载于:https://www.cnblogs.com/apollo1616/p/9516879.html

你可能感兴趣的:(python)