how to decide whether or not we want to create instance in python

Solutions on MaxInterview for how to decide whether or not we want to create instance in python by the best coders in the world

showing results for - "how to decide whether or not we want to create instance in python"
Diego Alejandro
09 Jan 2018
1def createInstance():
2    # Do what ever you want to determine if instance can be created
3    return True 
4
5class CustomizeInstance(object):
6    def __new__(cls, a, b):
7        if not createInstance():
8            raise RuntimeError, "Count not create instance"
9        instance = super(CustomizeInstance, cls).__new__(cls, a, b)
10        instance.a = a
11        return instance
12
13    def __init__(self, a, b):
14        pass