python attribute decorator

To create a decorator in python is really easy. If you apply hello_world_decorator to say any method, it will execute the wrapper first.


def hello_world_decorator(func):
    def wrapper(*args, **kwargs):
        print("Hello, world")
        return func(*args, **kwargs)
    return wrapper

class Employee(BaseModel):
    name: str
    id: int

    @hello_world_decorator
    def hello(_self):
     print("emplyoee")


 So you will get the following output

Hello, world

employee



Comments

Popular posts from this blog

gemini cli getting file not defined error

NodeJS: Error: spawn EINVAL in window for node version 20.20 and 18.20

vllm : Failed to infer device type