THIS Will Scare Python Devs #python #code #programming

preview_player
Показать описание
This will scare Python devs. #programming #code #python
Рекомендации по теме
Комментарии
Автор

when you think you know the extent of python's cursedness is it always proves you wrong

chri-k
Автор

that is horrifically brilliant and i love it

yellowsaint
Автор

I was reminded of this video today by someone who did not understand it and it made me realise the explanation of what is happening does not make any sense.

"I'm going to create a lamda with an underscore which calls that lamda immediately".

That's not it. You create a lamda which takes a function `_` as a parameter, and you call that function `_` in the body of the lambda. Then the decorator applies your lamda with the function that is defined beneath it. and assignes the result of this invocation to the name `start_time`. That's what's happening.

The immediately invoked part of the video is the property of using the lamda as a decorator because any decorator is always invoked the moment you use it and the lambda invokes its parameter the moment it is itself invoked. The fact that a value is assigned to what normally would hold a function is due to the fact the function `_` is called instead of being returned, as would normally be done with decorators.

Hope this helps

ApprendreSansNecessite
Автор

It's one of those things you wish to use in a codebase but you know it will make it unreadable

poijmc
Автор

When a JavaScript programmer meets python

Israel
Автор

Now I want to put this somewhere in our code just to prank the fellow devs lmao 😂

papuce
Автор

Now, functions can act as property without having to be a method of a class

cevucty
Автор

Great. No one should ever think on using it

motbus
Автор

Why can’t the start_time function just be defined and then right under it we have “start_time = start_time()”?

jackalakalaka
Автор

It looks like a way how to make your own "keywords" in Python. :D

tomasslavik
Автор

Well, if you really understand decorators it is not weird at all, it's like creating the function and then saving its own result value on its own name. Something like:
Start_time = start_time()

Since the function returns a string, from now on start_time is a string

darske
Автор

Is it really a variable? Can you change it?

volodyanarchist
Автор

nice!
its like the decorator that runs on any exit contidion

YoKKJoni
Автор

means with this code we no need to set up a variables to collect the data that return from start_time function right? That is great, thank you

kianmengkuak
Автор

Hey @indently it would be better if you also explain it’s practical real world use case Thnks

programmershourya
Автор

Someone can explain it to me how this work

memoking
Автор

This looks pretty similar to LazyStatic or LazyCell in Rust. If I'm not wrong, it desugars into a function under the hood, but you would use it no different to calling a static Variable.

I think one realistic use case is loading the System's language (which woukd explain why would Windows prompt some apps might need to be restarted so to reflect language changes)

Edit: Typos

antoniong
Автор

Just execute that code at the top of the module… you’ve created a variable with extra steps

joshdean
Автор

I would like to see the unit tests for this... all of the viable ones... haha

smackdatascot
Автор

Nothing to do with “abusing decorators” and completely useless. Just declare the date variable when your code starts, it will achieve the same thing.

chrisl.