re: Using Python Functions As Classes VIEW POST


Nice one :)

By the way you can turn classes into functions too:

class Foo:
    def __call__(self, a):
        print(f"Calling with a=", a)

foo = Foo()

Great! That's the needed comment to complement this article!


By the way you can do this:

In [1]: return_hello = lambda *args, **kwargs: 'hello'                   

In [2]: class Foo(metaclass=return_hello): ...                           

In [3]: Foo                                                              
Out[3]: 'hello'
code of conduct - report abuse