Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Challenge: Logging Decorator | Mastering Python Decorators
Functional Programming Concepts in Python
Sección 4. Capítulo 2
single

single

Challenge: Logging Decorator

Desliza para mostrar el menú

Note
Note

You can use the __name__ attribute of any function object in Python to get its name as a string. When writing a decorator, access the decorated function's name using func.__name__ inside the wrapper. This is useful for logging or debugging.

Tarea

Desliza para comenzar a programar

Write a decorator that prints the name of the function being called and its arguments:

  • Use the function's __name__ attribute inside the wrapper to access its name;

  • Print the args tuple for positional arguments and the kwargs dictionary for keyword arguments;

  • Return the result so the decorator does not change the function's behavior.

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 4. 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

some-alt