You are assigned a task to implement a decorator that logs the arguments and return value every time a function is called. How would you implement this logging decorator?
- Define a decorator function that wraps the original function, prints arguments, calls the function, prints return value, and returns the result.
- Modify the function itself to log arguments and return values.
- Use a built-in Python module like logging to log function calls automatically.
- Use a third-party library like Flask to create a logging decorator.
To implement a logging decorator, create a decorator function that wraps the original function, logs the arguments, calls the function, logs the return value, and returns the result. This is a common use case for decorators.
Loading...
Related Quiz
- In Flask, how would you access the data sent with a POST request?
- You have to develop a Django app that should be able to handle multiple databases. How would you configure the app to work with multiple databases?
- How would you create an instance of a metaclass in Python?
- In Python’s unittest framework, the ____ method is used to compare whether two values are equal.
- In Django, how can you store static files, like CSS or JavaScript, so that they can be served efficiently?