Python Decorators 2: Decorators with arguments

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

I watched many videos about decorators, and I didn't understand decorators until I came across your video. Thanks Sebastian. You are a good teacher ;)

Yousifalzoubi
Автор

Thanks Sebastiaan, your Python video tutorials is really the best.

serjikisagholian
Автор

Helped me a lot in a project im working on. Thanks!

YellowCardx
Автор

Found the eyebrow thing at 3:13 hilarious, hehe. But fun aside, you are a great teacher, than you very much for your videos.

Superogobongo
Автор

I agree with Serjik, your tutorials are very good. I finally grokked decorators, thanks.

rickklein
Автор

Sir, i admire of your ability to explain.

evgenykuznetsov
Автор

Heel mooi! Ik vind deze uitleg over decorators met argumenten duidelijker dan die van Corey Schafer :)

Erwipro
Автор

Thank you again for this very detailed and powerful decorator class! I love it! And it is elegant enough!

liuyu
Автор

Thanks amazing explaination doubts cleared

darshanv
Автор

I feel like decorators could be very useful and elegant especially in large software projects but for some reason I can't really think of a concrete use case. Could someone give an example where the real benefits of decorators are shown?

Btw: found your channel recently and love it!

Endredos
Автор

Another great video. I agree that the solution presented is not particularly elegant.

However, the explanation was!

Thanks!

thebuggser
Автор

Very interesting Sebastiaan, thank you very much.

srinivasaraoyp
Автор

I'm on fire today !! Thank You Sebastiaan !!

slimyelow
Автор

We can also use parameters like this:


def power_of1(func):
def inner(param=2):
return func() ** param

return inner


@power_of1
def random_odd_digit1():
return random.choice([1, 3, 5, 7, 9])


print(random_odd_digit1())
print(random_odd_digit1(3))






def power_of_something(func):
def inner(param=2):
return func(param)

return inner


@power_of_something
def random_func(power):
return random.choice([1, 3, 5, 7, 9]) ** power



print(random_func())
print(random_func(3))



 It not requires any additional checks whether the parameter is a callable object.



You have great tutorials, concise, easy to understand and code is very creative. May be after those three tutorials I will start to use decorators, because I always have known that them exist but actually never had used them and most important, didn't understand why do I need all this humbug.

But after this explanation it looks like it is can be some usefulness in this stuff.

deserve_it
Автор

Thank you very much for this detailed tutorial. But I am confused about how decorator (inside power_of) can know about fnc ! since there is no link between them !

MostafaMASLOUHI
Автор

So, that's how Flask makes that app.route() work?

AyushMandowara_xx
Автор

Thanks Sebastiaan, for this great tutorial. Can you please explain how one can implement class decorators with optional arguments, for example, as we have in functools LRU_cache?

judeleon
Автор

Could someone explain, how to decorate function with a decorator, that takes paramteres like this while not using the @. I don´t get how Python understands, that it is the function below the @decorator, it is supposed to take as argument.

adamstrejcovsky
Автор

I can't get decorators to work with instance methods

petrockspiracy
Автор

At some case you might think that decorated functions are like js callbacks

Maxiker