To wrap a function imported from another file with @Decorator

Asked 2 years ago, Updated 2 years ago, 78 views

file 1

def file1_fun():

file2

from file1 import file1_fun

def deco(target):
    "Decorated"Yes")

    def wrapper():
        Sentences to execute first
        result = target()
        Sentences to run later

    return wrapper 

@deco
file1_fun() <----------------- This doesn't make sense. It's not the Declaration, it's the Executive Branch.

Like this, how can you cover a decorator if you simply import an externally declared file?

python decorator

2022-09-22 11:44

1 Answers

Self-answer

from file1 import file1_fun
file1_fun = deco(file1_fun)

https://stackoverflow.com/questions/25829364/applying-a-decorator-to-an-imported-function


2022-09-22 11:44

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.