def Func():
pass
In an IPython session, when I enter type(Func) the output is "function". As Python is an object oriented language, I assume there is a class of which "Func" is an instance. So I tried creating my own class this way:
class MyFunc(function):
pass
Alas, the interpreter just threw a "NameError" complaining that "function" is not defined. So, I tried being a little clever and did this:
class myfunc(func.__class__):
pass
Alas, it failed miserably...
TypeError: Error when calling the metaclass bases
type 'function' is not an acceptable base type
In summary, could anyone explain: 1). How to create a class derived off of the type "function". If not possible, why? 2). What that error message really meant.
In summary, could anyone explain: 1). How to create a class derived off of the type "function".
You can't.
If not possible, why? 2). What that error message really meant.
That error message means that Python won't let classes use the function type as a base class. Classes implemented in C can only be extended if they set a specific flag; if they don't, this is the error you get when you try to extend them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With