Table of Contents
About Meta
To see a bit more about inner of python
type & object & class & instance
https://stackoverflow.com/questions/100003/what-are-metaclasses-in-python
https://www.zhihu.com/question/38791962
instance’s class
print('"hello world".__class__:', 'hello world'.__class__)
"hello world".__class__: <class 'str'>
class’s class and parents
print('str.__class__:', str.__class__)
print('str.__bases__:', str.__bases__)
str.__class__: <class 'type'>
str.__bases__: (<class 'object'>,)
type’s parent
type.__bases__
(object,)
__call__'s role in class and type
class SimpleMeta(type):
def __call__(self, *args, **kwargs):
print("callable object called()")
return super().__call__(*args, **kwargs)
def __new__(cls, clsname, bases, clsdict):
print('SimpleMeta.__new__')
return super().__new__(cls, clsname, bases, clsdict)
class Spam(object, metaclass=SimpleMeta):
def __init__(self):
pass
def __new__(cls, *args, **kwargs):
print('Spma __new__')
return super()</