python - Determinate if class has user defined __init__ -
i'm trying identify if class received via argument has user defined __init__
function in class passed. not in super class.
class hasinit(object): def __init__(self): pass class noinit(object): pass class base(object): def __init__(self): pass class stillnoinit(base): pass def has_user_defined_init_in(clazz): return true if # magic assert has_user_defined_init_in(hasinit) == true assert has_user_defined_init_in(noinit) == false assert has_user_defined_init_in(stillnoinit) == false
i think work:
def has_user_defined_init_in(clazz): return "__init__" in clazz.__dict__
Comments
Post a Comment