Add THIS To Your Python Scripts!  if __name__ == "__main__"

Add THIS To Your Python Scripts! if __name__ == "__main__"

b001

2 года назад

179,089 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@humzaashraf321
@humzaashraf321 - 30.03.2023 22:21

This is the simplest and clearest explanation I've come across for this. Thank you!

Ответить
@vishweshthotakuri6144
@vishweshthotakuri6144 - 06.06.2023 17:18

Hey do you have any course on udemy for python

Ответить
@philipberthiaume2314
@philipberthiaume2314 - 24.06.2023 04:44

Or you can remove the method call in Script1, import in Script2 and call the do_something() function from there.

Ответить
@marcuswest8085
@marcuswest8085 - 01.07.2023 20:23

Well_paced explanations...

Ответить
@saimqazi1663
@saimqazi1663 - 03.07.2023 06:28

Bro Your the best

Ответить
@usprpc
@usprpc - 16.07.2023 17:49

Nice fact

Ответить
@PopsFizzle-wz5jd
@PopsFizzle-wz5jd - 27.07.2023 14:15

I need the name of that theme please

Ответить
@fanoflinoa6109
@fanoflinoa6109 - 10.08.2023 08:03

That’s a very useless example

Ответить
@ivanichianus
@ivanichianus - 20.08.2023 08:49

watched a few other videos of this topic and yours was the most simple to understand, thank you!

I wish you had a full Python course video, would love to watch you guide us through from the very basic beginnings to more complex stuff in Python.

Ответить
@zero_day_xsploit
@zero_day_xsploit - 29.08.2023 00:06

all the 30 min videos and this was the best

Ответить
@aryangupta7703
@aryangupta7703 - 28.09.2023 20:16

Thanks, Awesome crystal clear explanation

Ответить
@elshanmammadli7731
@elshanmammadli7731 - 08.10.2023 17:27

Thanks a lot. Got it now.

Ответить
@wh1pper457
@wh1pper457 - 18.10.2023 22:05

this was the explanation i needed. thank you

Ответить
@vladthecoldone8804
@vladthecoldone8804 - 26.10.2023 21:40

or you could simply not call the function in the module from which you import? can someone please explain to me why is it needed? I guess I know what it does, syntax and whatnot but simply put, if youre not calling the functions/methods in not main module, why would you even use it when it doesnt run automatically?

Edit: okay I see it, useful only when you need to use it as a standalone script for testing so you can have bunch of function calls ready at hand otherwise no need if you aint calling it and why would you even call it or make print statements there since thats whats main module for

Ответить
@anj19911
@anj19911 - 07.11.2023 01:10

this is the third video on _name_ that i watched and it was the icing on the cake. i now fully understand what the purpose is, thank you so much!!!!!!!!!!!!!!!!!!

Ответить
@scrambledmc3772
@scrambledmc3772 - 09.11.2023 01:12

I don't get it. You're calling the function in both files but you only want it to run in one? What's the point of that? When would you ever need this?
Point is, any code you want to run in only one file should only be written in that file. This can be applied similarly to variables knowing their own name.

Ответить
@AdvForTimeFrever
@AdvForTimeFrever - 18.11.2023 15:28

i have a dumb question.
why dont just remove " do_something() "

Ответить
@PradipLamsal-s8m
@PradipLamsal-s8m - 01.12.2023 03:16

Simple and useful explanation. Thanks. :)

Ответить
@HenrikMyrhaug
@HenrikMyrhaug - 14.12.2023 00:42

I wish there was a keyword for this. *if "__name__" == "__main__":* is just such an eye-sore.

Ответить
@callyral
@callyral - 15.12.2023 23:53

ikd python but wouldn't it be easier to add a guard clause before the "main execution" testing if it's NOT "__main__" and exiting if that's the case? so that your code isn't all indented

Ответить
@yuvanraj6226
@yuvanraj6226 - 22.12.2023 00:00

nee alutham lae

Ответить
@ramnivas5252
@ramnivas5252 - 30.12.2023 11:19

Bro you are awesome

Ответить
@AMMIN13
@AMMIN13 - 04.01.2024 13:05

that is super simple. Really amazing!

Ответить
@brunoroda3437
@brunoroda3437 - 04.01.2024 14:23

When you learning, sometimes you just need little videos to have a whole new understanding of what you're doing :D thank you so much

Ответить
@djangoworldwide7925
@djangoworldwide7925 - 04.01.2024 16:28

Why wouldn't you remove the call to do something in script1 instead? Well I guess there are other real life complex situations where this is useful. Thanks it was straightforward

Ответить
@mamadoubah3143
@mamadoubah3143 - 06.01.2024 17:06

god, i have finally understood it

Ответить
@mccauleybacalla2228
@mccauleybacalla2228 - 17.01.2024 19:28

As a beginner, i am confused fr

Ответить
@CornFlaekk
@CornFlaekk - 12.02.2024 18:33

What theme do you use for VSCode? It looks so good

Ответить
@superben754
@superben754 - 12.02.2024 22:28

amazing..! Thank you for the video!

Ответить
@ajax_og
@ajax_og - 13.02.2024 01:13

I wish i saw this video LAST NIGHT when I was doing my homework and could not for the life of me figure out how to not get my code to run twice... well you live and you learn lmao

Ответить
@ekanshjaiswal9976
@ekanshjaiswal9976 - 18.02.2024 14:06

Interesting . . . .

Ответить
@Bl0xxy
@Bl0xxy - 25.02.2024 22:37

100% i'm not gonna put this in ALL my scripts. i'm going to make sure to only use them in scripts that need to be imported

Ответить
@iurymikaelsobraldossantos646
@iurymikaelsobraldossantos646 - 26.02.2024 21:05

What theme are you using on vscode?

Ответить
@gopal.
@gopal. - 28.03.2024 21:27

gawd I love you

Ответить
@DMZT_dhruv
@DMZT_dhruv - 30.05.2024 13:22

Which Font are you using?

Ответить
@mercantilism954
@mercantilism954 - 25.06.2024 05:59

I watched several videos yet still don't understand. my low iq

Ответить
@nearyou30
@nearyou30 - 11.07.2024 03:43

Possibly the most concise and clear explanation of this variable!

Ответить
@lilyempire
@lilyempire - 15.08.2024 13:15

Finally. A very simple yet straightforward explanation. Thank you

Ответить
@s.hamedstriker5315
@s.hamedstriker5315 - 18.08.2024 10:16

finally! an explanation to the use not complicated mechanism!

Ответить
@rryann088
@rryann088 - 26.08.2024 18:10

C L E A N E S T 🔥🔥🔥🔥🔥🔥🔥🔥🔥

Ответить
@erickthamara5154
@erickthamara5154 - 01.09.2024 21:49

Short and sweet,thanks

Ответить
@ramarisonandry8571
@ramarisonandry8571 - 26.09.2024 14:03

Incredible

Ответить
@ironmonkey1990
@ironmonkey1990 - 29.09.2024 02:27

thank you!

Ответить
@Moneyblueprint1
@Moneyblueprint1 - 03.10.2024 00:54

ty

Ответить
@promixinc.8434
@promixinc.8434 - 15.10.2024 16:40

I think main guards are good to implemented in every script.

Ответить
@snoozing7725
@snoozing7725 - 21.10.2024 13:28

For anyone wondering "Dunder" means double underscore

Ответить
@MeguVusion
@MeguVusion - 22.11.2024 01:33

My question is how are you getting Python to output under Output and not the Terminal?

Ответить