memory_storage
append
/
print_hello
输出:
import functools
memory_storage = []
def memory(func_names, description):
def decorator(func):
# This should be put here
memory_storage.append({
"func_names": func_names,
"description": description,
"function": func
})
@functools.wraps(func)
def wrapper(*args, **kwargs):
return func(*args, **kwargs)
return wrapper
return decorator
@memory(
func_names=['print_weep'],
description="This method will print the weep"
)
def print_weep():
print("weep")
@memory(
func_names=['print_hello'],
description="This method will print hello"
)
def print_hello():
print("hello")
def execute_functions():
for entry in memory_storage:
print(f"Executing function {entry['func_names'][0]}: {entry['description']}")
entry['function']() # Call the stored function
print("Stored Metadata:", memory_storage)
execute_functions()