class object def __init__ self args kwargs if self foo 42 raise Except

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
>>> class A(object):
... def __init__(self, *args, **kwargs):
... if self.foo != 42:
... raise Exception("You get the answer and than call me, KAPISH?")
... @classmethod
... def simpleconstructor(cls, *args, **kwargs):
... return object.__new__(cls, *args, **kwargs)
...
>>> A.simpleconstructor()
<__main__.A object at 0xb7d705ac>
>>> A()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in __init__
AttributeError: 'A' object has no attribute 'foo'