Good day,<br /><br />I want MyClass to perform some tests and if them fail, I do not want instance to be created. <br /><br />But in code I wrote instance is created and also has parameters, that it should not have in case of tests failure.<br /><br />Is there a way to perform tests in MyClass.__init__ and set instance to None without any parameters?<br /><br />I do not want che code outside MyClass.__init__ to know anything about tests performed, and make decision to allow or prevent instance creation.  <br /><br />The code I wrote is:<br />******************************************************<br />class MyClass():<br />    <br />         def __init__(self):<br />                      self.param = "spam"<br />                      Test = False<br />                               if Test == True: <br />                                          print "Creating instance..."<br />                               return <br />                         else:<br />                                          print "Instance creation not allowed..."<br />                                          self = None<br />                                          return None<br />        <br />        <br />a = MyClass()<br />print a<br />print a.param<br />*************************************************<br /><br />Thanks,<br />Aigars<br />
<!--                                                                                                                                                                                                                                                                                                                      -->