Challenge: Logging Class Creation
Now that you have learned how to define custom metaclasses, you can use their __new__ or __init__ methods to run code every time a new class is created. By placing a print statement in either of these methods, you can observe when and how Python constructs classes that use your metaclass. This is a powerful technique for debugging, inspecting, or instrumenting class creation in complex codebases, as it gives you visibility into the metaclass machinery at work.
Swipe to start coding
Create a metaclass named LoggingMeta that prints the name of every class it creates. When you define a class using LoggingMeta as its metaclass, it must print a message in the format Creating class: <ClassName>, where <ClassName> is replaced with the name of the class being defined. The message must be printed only during class creation, not when creating instances of the class.
Solución
¡Gracias por tus comentarios!
single
Pregunte a AI
Pregunte a AI
Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla
Genial!
Completion tasa mejorada a 4.76
Challenge: Logging Class Creation
Desliza para mostrar el menú
Now that you have learned how to define custom metaclasses, you can use their __new__ or __init__ methods to run code every time a new class is created. By placing a print statement in either of these methods, you can observe when and how Python constructs classes that use your metaclass. This is a powerful technique for debugging, inspecting, or instrumenting class creation in complex codebases, as it gives you visibility into the metaclass machinery at work.
Swipe to start coding
Create a metaclass named LoggingMeta that prints the name of every class it creates. When you define a class using LoggingMeta as its metaclass, it must print a message in the format Creating class: <ClassName>, where <ClassName> is replaced with the name of the class being defined. The message must be printed only during class creation, not when creating instances of the class.
Solución
¡Gracias por tus comentarios!
single