Aigars Aigars wrote:
if you want construction to fail, raise an exception.
...
def __init__(self):
self.param = "spam"
Test = False
if Test: # please don't use explicit tests for truth
print "Creating instance..."
else:
raise ValueError("som e condition failed")
(pick an exception class that matches the actual error, or create your
own class if necessary)
</F>
I want MyClass to perform some tests and if them fail, I do not want
instance to be created.
>
But in code I wrote instance is created and also has parameters, that it
should not have in case of tests failure.
>
Is there a way to perform tests in MyClass.__init_ _ and set instance to
None without any parameters?
instance to be created.
>
But in code I wrote instance is created and also has parameters, that it
should not have in case of tests failure.
>
Is there a way to perform tests in MyClass.__init_ _ and set instance to
None without any parameters?
...
def __init__(self):
self.param = "spam"
Test = False
if Test: # please don't use explicit tests for truth
print "Creating instance..."
else:
raise ValueError("som e condition failed")
(pick an exception class that matches the actual error, or create your
own class if necessary)
</F>