L
Lacrima
Hello!
For example I have two classes:
def __init__(self, *args, **kwargs):
pass
def __init__(self, somearg, *args, **kwargs):
self.somearg = somearg
How can I test that First class takes 1 required argument and Second
class takes no required arguments?
So that I could instantiate them in a for loop.
Traceback (most recent call last):
File "<pyshell#22>", line 2, in <module>
instance = cls()
TypeError: __init__() takes at least 2 arguments (1 given)
Of course, I can do like this: try:
instance = cls()
except TypeError:
instance = cls('hello')
hello
But what if I have to instantiate any class with 3 or 4 required
arguments? How can I do it?
With regards,
Max
For example I have two classes:
def __init__(self, *args, **kwargs):
pass
def __init__(self, somearg, *args, **kwargs):
self.somearg = somearg
How can I test that First class takes 1 required argument and Second
class takes no required arguments?
So that I could instantiate them in a for loop.
instance = cls()a = [First, Second]
for cls in a:
Traceback (most recent call last):
File "<pyshell#22>", line 2, in <module>
instance = cls()
TypeError: __init__() takes at least 2 arguments (1 given)
Of course, I can do like this: try:
instance = cls()
except TypeError:
instance = cls('hello')
hello
But what if I have to instantiate any class with 3 or 4 required
arguments? How can I do it?
With regards,
Max