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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

python - Django-cities exits with "killed" -

python - How to get a widget position inside it's layout in Kivy? -