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

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -