class - In Python, Return “None” instead of creating new instance if wrong parameters are given -
when creating instance of class, if wrong parameters given. how i not create new instance , return reference, instead return "none"
here application: because allowed sometime. application build trees list of integers. want use none in list represent leaf. want return none instead of empty tree node.
see this answer python __init__
return failure create.
basically, can use __new__
accomplish want, really, pythonic way of doing throw exception. arguably, pythonic way have simpler __init__
method initialization , not can fail @ all.
Comments
Post a Comment