Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Challenge: Logging Class Creation | Custom Metaclasses in Action
Python Metaclasses Demystified

bookChallenge: 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.

Tarea

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

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 2
single

single

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

close

bookChallenge: 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.

Tarea

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

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 2
single

single

some-alt