T
T
Themidis Koudes2022-01-24 17:25:44
Python
Themidis Koudes, 2022-01-24 17:25:44

How to create your own function class?

I want to create a child class from the built-in function class, but I can't access it.

class my_func(function) :
    pass

This code doesn't work, python writes that it doesn't know what function is.
Just in case, this is done in order to add a wrapper to functions, but since there are many functions, I don’t want to add the same piece of code to each one.
Perhaps this can be done with decorators, but I don't know how.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Adamos, 2022-01-24
@Adamos

The __call__ magic method allows you to make any object a function without any inheritance.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question