by Anonymous » 02 Feb 2025, 07:52
Hier ist mein Python -Code, den ich versuche. Ich erwarte gespeicherte Metadatenliste.
Code: Select all
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()
Hier ist mein Python -Code, den ich versuche. Ich erwarte gespeicherte Metadatenliste.[code]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()
[/code]