single
Challenge: Logging Decorator
Pyyhkäise näyttääksesi valikon
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.
Pyyhkäise aloittaaksesi koodauksen
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
argstuple for positional arguments and thekwargsdictionary for keyword arguments; -
Return the result so the decorator does not change the function's behavior.
Ratkaisu
Kiitos palautteestasi!
single
Kysy tekoälyä
Kysy tekoälyä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme