[Python] How do i execute the python function using decorator metadata without calling...

Discussão em 'Python' iniciado por Stack, Fevereiro 2, 2025.

  1. Stack

    Stack Membro Participativo

    here is my python code i am trying. I am expecting Stored Metadata list. Memory Decorator Purpose is the code where functions are "decorated" to store metadata.

    import functools

    memory_storage = []

    def memory(func_names, description):
    def decorator(func):
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
    # Store the metadata before function execution
    memory_storage.append({
    "func_names": func_names,
    "description": description,
    "function": func
    })
    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()

    Continue reading...

Compartilhe esta Página