Given the following example on an instance of a X
class:
class X():
def __call__(self, incoming_list):
print incoming_list
X()([x for x in range(10)])
How can I obtain the same output by using the __call__
magic method from the class itself instead of the instance? Example:
X([x for x in range(10)])
Calling directly, as if passing to __init__
. But, before it calls __call__
that calls __new__
that passes the arguments to __init__
. How can I access that "metaclass __call__
" ? Is it possible?
Just to make it easier to understand, this gives me the same output from up there:
class X:
def __call__(self, incoming_list):
print incoming_list
X().__call__([x for x in range(10)])
I want something like this:
class X:
def X.__call__(incoming_list): # Syntax Error
print incoming_list
X.__call__([x for x in range(10)])