Can you give a example for Python meta class
时间: 2023-04-09 19:01:24 浏览: 96
Sure, here's an example of a Python metaclass:
```
class MyMeta(type):
def __new__(cls, name, bases, attrs):
# Do some custom logic here
return super().__new__(cls, name, bases, attrs)
class MyClass(metaclass=MyMeta):
pass
```
In this example, `MyMeta` is a metaclass that is used to create the `MyClass` class. The `__new__` method of `MyMeta` is called when `MyClass` is defined, and it can be used to customize the creation of the class.
阅读全文