Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Impara Challenge: Logging Decorator | Mastering Python Decorators
Functional Programming Concepts in Python
Sezione 4. Capitolo 2
single

single

Challenge: Logging Decorator

Scorri per mostrare il menu

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.

Compito

Scorri per iniziare a programmare

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.

Soluzione

Switch to desktopCambia al desktop per esercitarti nel mondo realeContinua da dove ti trovi utilizzando una delle opzioni seguenti
Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 4. Capitolo 2
single

single

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

some-alt