Decorator with functools.wraps
Write a decorator @logcall that prints "Calling <function name>" before calling the wrapped function, using @functools.wraps to preserve the original function's metadata, then confirm name_ survives decoration.
Approach: define logcall using functools.wraps(func) inside its wrapper, apply it to a greet(name) function, call greet with the given name, and print greet.name_ afterward.
Input: One line: a name.
Output: Three lines: "Calling greet", "Hello, <name>!", and the decorated function's name ("greet").
Aditi
Calling greet Hello, Aditi! greet
- name is a non-empty string with no newline
Hint 1
@wraps(func) goes directly above the inner wrapper function definition.
Hint 2
Print the "Calling ..." message inside wrapper, before calling func(*args, **kwargs).
Hint 3
Without @wraps, greet.__name__ would incorrectly print "wrapper" instead of "greet".
wrapper prints "Calling greet" before delegating to the real greet(name), so both the log line and the actual greeting appear in order. @wraps(func) copies func's name (and doc) onto wrapper, so greet.name after decoration still correctly reports "greet" instead of "wrapper".