This is the most underrated video/channel I've ever seen
@fuwadhasan3 жыл бұрын
Agree
@vaani63934 жыл бұрын
You came like a saviour in my search options
@Tptkk6 жыл бұрын
I'm blown away by your videos! So much information and on top of that presented in a digestible way. Very unique. You got talent! Thanks! Keep up the great work! Greetings from Germany
@macacinelecanale2 жыл бұрын
The clearest explanation of decorators video that I found, and watched a lot of them! You have very good teaching skills!
@rajburtonpatel6702 Жыл бұрын
I love the way you write list comprehensions from the inside to out. Really helps get them right and explain them well.
@Naton4 жыл бұрын
I love the pace. Followed without pausing
@andreashohmann9573 жыл бұрын
Best explanation i have seen so far!!!
@programaticamentefalando29183 жыл бұрын
When the explanation is hard to understand there is bitty chance the conveyor of the information does not have much knowledge about the topic himself. Which, is not the case here. Agreed.
@nareshgb15 жыл бұрын
Flat out the best video on decorators - a REAL, USEFUL example. Awesome.
@JeremyFisher4 жыл бұрын
Good Video, yes useful ? no for word in names: print(camelcase(word))
@satoshinakamoto1714 жыл бұрын
probably the best tutorial on decorators on yt. deserves more views
@brucewu18434 жыл бұрын
Wow this guy exactly knows what the audience wants. 10/10. good job man!
@antonyinjila71523 жыл бұрын
This guy;s teaching style is on another level. Thank you for the time and effort .
@stevenwilson55562 жыл бұрын
well said. I hope you do *many* move videos. You should consider teaching this stuff if you don't already.
@thebuggser27523 жыл бұрын
What a great presentation! I’ve been looking for a good explanation of what a decorator is, and this nailed it! A home run! Thanks!
@stevenwilson55562 жыл бұрын
Agree with this.
@joebater78304 жыл бұрын
The first three minutes of this explained what I've been struggling with from multiple books and other videos! bravo!
@sheikhakbar20674 жыл бұрын
Thanks for the example; it illustrated the concept of decorators perfectly!
@aaronbaldwin28453 жыл бұрын
You are such a great conveyer of information. Very concise and understandable. I appreciate these videos
@francescodiniccolo6 жыл бұрын
I finally properly understood what a decorator is. Thank you!
@stevenwilson55562 жыл бұрын
Brilliant video, well explained.. was able to duplicate what you did and I am still a raw beginner only been trying to learn Python for about a week give or take. Thank you.
2 жыл бұрын
Glad to hear you find it useful!
@classicrockonly5 жыл бұрын
This is probably the first video that has made decorators make sense to me. Thank you!
5 жыл бұрын
Glad you found it useful!
@audioplatform62996 жыл бұрын
Just want to say 2 words... "Thank you".... was trying to understand this for a while and finally i got it!!
@PrakashReddyK5 жыл бұрын
Thanks for the wonderful job of explaining the decorators in a precise and crystal clear way. Thanks a ton
@naveenkalhan954 жыл бұрын
watched lots of tutorials that were explaining the python decorators!!! had to close videos one by one because they were explaining in such a complicated way! you really explained the same in such a simple way,... that even a non-programmer can understand as well :)) thank you very much
@rahulmistri19973 жыл бұрын
Thank you it was really a concise explaination. Subscribed
@AyushMandowara_xx74 жыл бұрын
Hey, Very nicely explained! I finally understand what decorators are. One small thing though, what you are returning is actually PascalCase and not camelCase. Thanks!
@fuanka17246 жыл бұрын
Decorators can be quite complex sometimes, but this intro is perfect. Great video as always, thanks. Looking forward to seeing more on this topic.
@minhhuynhthe Жыл бұрын
Great work🎉!
@baldebalde97903 жыл бұрын
Finally got the concept, thanks
@jameslovering91585 жыл бұрын
Thanks very clear and I now understand alittle more today.
@abhisek.g.mahapatra5 жыл бұрын
Concise and very well explained. Thanks for your efforts in creating these videos - really helpful.
@alexandermedina49502 жыл бұрын
Great explanation, thank you.
@SuperAcousticDude3 жыл бұрын
Very well explained!
@cxsey85872 жыл бұрын
Very useful and practical
@jameszaman3326 Жыл бұрын
That was a VERY good tutorial!
@nerdvananc3 жыл бұрын
Thanks a ton! I watched your video on asyncio and immediately subscribed, and now this is the fifth video on your channel I'm binging. I had a question though; adding the @mapper decorator to camelcase() works very well for when its passed lists, but breaks the original functionality camelcase() was intended for: which was to convert *strings* into CamelCase. With the @mapper decorator, writing camelcase("some_string") returns a list of each of "some_strings" letters capitalized into a list. Isn't this incorrect?
@vilmm4 жыл бұрын
Excellent video
@officesuperhero96116 жыл бұрын
Just wanted to say thanks for this and other excellent videos. Great job!!
6 жыл бұрын
Thanks!
@arturomtz83 жыл бұрын
Keep up the good work! New subscriber from Mexico!
@wanderwithniraj5 жыл бұрын
super one of the best explanation of decorator. Loved it! :)
@vatsal_gamit3 жыл бұрын
This was amazing 🎉
@pradeep-he9jq3 жыл бұрын
Thank you. This was pretty clear explanation.
@bestest435 жыл бұрын
hi sir, what I did not understand what you have done is when I tried to put the first input as a string it gave me an error again. Maybe we handled list input problem but we lost string input control. It seems we changed the entire function internal structure. Instead of defining a decorator, I could define a list splitter function like you did and put that function before splitting the underscored string. Am I wrong? I did not get the purpose of a decorator.
@paulburger99044 жыл бұрын
I hate to be that guy, but this is actually Pascal case. Great tutorial by the way.
@Dualphase906 жыл бұрын
Sebastian Mathot back with the hip-hop names :)
@TheSuperHombre4 жыл бұрын
Nice explanation, thanks a lot.
@juliamihet42373 жыл бұрын
Awesome video! Just a small remark, ThisIsPascalCase, thisIsCamelCase (at least according to Microsoft) and this_is_snake_case. And this-is-kebab-case.
@rhyanz465 жыл бұрын
great tutorial,
@sunendran5 жыл бұрын
This is the perfect explanation.
@slimyelow5 жыл бұрын
This is really another Kickazz le$$on, watch, do and learn !!
@SamSarwat905 жыл бұрын
Dude, you are gold. Appreciated!
@onlysolo5 жыл бұрын
good video, clear explanations:)
@charlesbovalis65915 жыл бұрын
By the way - at 2:35 of this video - tried to follow along and typed the code as I see it .. and I was getting a lot of Name Errors ( It was complaining that "another_function" was not defined .. so the solution was to re-arrange the functions order as follows: def turn_into_another_function(fn): return another_function def another_function(): print('another function') def a_function(): print('a function') a_function = turn_into_another_function(a_function) a_function() Now it works ...
5 жыл бұрын
That's correct. I made a mistake in the video, but the downloadable notebook is correct. (In the video there is no error because of the way that the namespace is preserved in a notebook.)
@charlesbovalis65915 жыл бұрын
@ Thank you for your response Sebastian. I usually don't download stuff as I have plenty of "tools" already installed on my mac and so I type code as I see it on videos either straight on my interactive Python shell or using any of my code editors. Thank you for getting back to me. Nevertheless it was a good "challenge" to figure this out.
@sirberbe6 жыл бұрын
Thank you for your effort in doing excellent and useful videos I've learned a lot of things
6 жыл бұрын
Glad you learned something!
@Logan.Infinito5 жыл бұрын
Rappers in the camelcase, you rock !
@nivethanyogarajah1493 Жыл бұрын
Perfection
@ArjunUmathanu5 жыл бұрын
I do not understand how your decorator function (turn_into_another_function) returns the function (another_function) which is not declared yet in it's global scope. For me, I have to define the another_function above all. Only then I get the decorator works. Else, I get that function not defined error!!. Please correct me if I'm wrong.
5 жыл бұрын
That's correct-it's a bug in the video, so to say. The reason that it works in the video is that `another_function()` was already defined in the workspace because of what I did before. But if you run it from scratch you'll indeed get this error. This has been fixed in the notebook that you can find under the link below the video.
@ArjunUmathanu5 жыл бұрын
@ thank you
@曾玮-d8z Жыл бұрын
If 2:30 NameError: name 'another_function' is not defined. Did you mean: 'turn_into_another_function'? Solvation: move 'another_function' up to the most top
@syncwork2 жыл бұрын
How to get a mindset to written python code in such a small lines? For example, Below is the code snippet of camelcase function if it was written by me. def camelcase(s): # turn "this_is_a_string" into "ThisIsAString" splited_list = s.split('_') print(splited_list) camelstring = "" for word in splited_list: capital_word = word.capitalize() camelstring += "".join(capital_word) print(camelstring)
@sm4shqsm4shq606 жыл бұрын
Can someone explain why the original camelcase() isn't just hardcoded to behave differently in the first place? I get this is about dynamically altering functions, but I have a hard time seeing practical use in this, especially with the @syntax. For example, after applying the @mapper decorator, the original functionality of camelcase() is completely lost, no? Unless @mapper can somehow be "turned off", it can no longer handle a single string the way it used to...? This topic has me frustrated...
6 жыл бұрын
You never *need* decorators, because, as you say, you can also write a new function or directly modify the original function. However, a decorator is a convenient way to add functionality to many different functions. Caching is a good example of this. Say that you have thirty functions that all perform time-consuming operations. To speed things up, you could then build caching into each function separately. But a decorator allows you to do this more elegantly, by applying a caching decorator to all the functions. So that would be one use case. Such use cases, where decorators really help, are fairly rare, but you do run across them every once in a while!
@vvega51715 жыл бұрын
Hi. Thank you very much for this explanation. Now I am very clear with Decorators. One last thing. What if I want to use the function for only one string?. For instance 'hello_world'. The output is not the one I expected. I got this ['H', 'E', 'L', 'L', 'O', '', 'W', 'O', 'R', 'L', 'D'] and not this HelloWorld I assume the purpose of the Decorator is to use the function only for list of strings and not for a single string.
5 жыл бұрын
In Python, a string is very similar to a list of individual characters, and that's how the decorated function is treating it. If you want to process a single string, you can turn it into a list of only one ['string']. Or rewrite the decorator so that it checks whether the argument is a list or a string, and then handles the situation accordingly!
@vvega51715 жыл бұрын
@ Thanks again! That is what I wanted to know. That I will never use the decorated function anymore. Instead, I will use the decorator functionality.
@LuvxJacqu4li8e Жыл бұрын
Thanks
@tshaylatte95024 жыл бұрын
Thank you!
@felipica2 жыл бұрын
valeu mano ajudou demais tmj
@santoshloke4 жыл бұрын
b-e-a-utiful
@sheikhakbar20673 жыл бұрын
I keep coming to this video when I forget how decorators work.
@CodingMazaa6 жыл бұрын
Brilliant!! awesome!!!
@liridonsejdiu61105 жыл бұрын
you sir made my day thnx
@Lapinoire4 жыл бұрын
I think i understand the premise of a decorator, but i don't understand why you wouldn't just for loop through the list like: for name in names: camelcase(name) print(name) I understand its a decorator explanation, but don't see the value in using a decorator?
@diouranke5 жыл бұрын
Is this related to assert
5 жыл бұрын
I'm assuming that you're referring to the `assert` statement, which is a kind of sanity check that crashes the program when a certain condition is not met. So no, that's not really related to decorators!
@michaelshort2388 Жыл бұрын
Camel case actually has the first word with no capital. :)
@renegadevi88826 жыл бұрын
I find the @staticmethod pretty useful.
6 жыл бұрын
It is! I actually have a video on the topic: kzbin.info/www/bejne/q6HQgHSGoJeWgZo
@mafridi1066 жыл бұрын
I keep getting this error: # python test.py Traceback (most recent call last): File "test.py", line 6, in a_function = turn_into_another_function(a_function) File "test.py", line 2, in turn_into_another_function return another_function NameError: global name 'another_function' is not defined This is what the code looks like: def turn_into_another_function(fnc): return another_function def a_function(): print('a function') a_function = turn_into_another_function(a_function) def another_function(): print('another function') a_function()
6 жыл бұрын
There was a bug in the notebook which I hadn't noticed! The fixed notebook is here: osf.io/szwhk/
6 жыл бұрын
There was a bug in the original notebook, but it's fixed now! osf.io/szwhk/
@yuliu11056 жыл бұрын
Hello Sebastiaan Mathôt, Thank you so much for this great tutorial. I don't quite understand one syntax in @mapper, func(value) for value in list_of_values, what is func(value)? Also, I believe camelcase is turn string_like_this to stringLikeThis. So this is my camelcase func def camelcase(text): a=[word for word in text.split('_')] return a[0].lower()+''.join([a[i].title() for i in range(1, len(a))])
6 жыл бұрын
fnc(value) is the actual function call, where fnc is the decorated function, and value is the function argument. And this is embedded in a list comprehension so that fnc is called once for each value from list_of_values. Does that make sense? And you're right about camelCase :-)
@yuliu11056 жыл бұрын
can I understand this way? func(value) is actually calling camelcase(s)? decorator is complicated.
6 жыл бұрын
Yes, exactly!
@vincentpiegsa6 жыл бұрын
Great video, but I get an error when executing the first example: line 3, in turn_into_another_function return another_function NameError: name 'another_function' is not defined I already checked for spelling mistakes, but everything seems to be fine. Can anyone help me with that?
6 жыл бұрын
Ah, thanks for pointing this out! I fixed the notebook: osf.io/szwhk/
@debvdo6 жыл бұрын
I wonder how it worked out in the video (2:40). You are defining another_function() after applying the decorator. Why didn't it give a NameError?
6 жыл бұрын
That's simply because another_function had already been defined in the workspace during a previous execution of the cell. But when running from an empty workspace it indeed couldn't work.
@kevinchang23 жыл бұрын
This is a really good tutorial but I still dont get it unfortunately
@erikschiegg686 жыл бұрын
👍
@havehalkow Жыл бұрын
Function, a function, another function, function, function decorator dizzy.
@ikhurramraza5 жыл бұрын
But why would you do this? Why not just update the camelcase function to accept list instead?
5 жыл бұрын
In general, decorators allow you to apply some common functionality to many functions, without having to explicitly implement this in each of the functions. So it's about modularity. Of course, this camelcase example is too trivial to really highlight the usefulness of decorators. But imagine for example a 'memoization' decorator that caches the results of a time-consuming function.