What does if __name__ == '__main__' do in Python?

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

I'm willing to bet that most of you have seen this code before, and probably have no idea what it actually does. In this short video, I'm going to break that down,

⏳ Timestamps ⏳
00:00 | The Problem
01:57 | The Solution
04:19 | Free Guide

Hashtags
#Python #PythonFunctions #SoftwareDevelopment
Рекомендации по теме
Комментарии
Автор

A perfect explanation 👌 I'm teaching Python to my little sister, and now I've got the perfect example to explain to her.

andrewtsegaye
Автор

Thanks for providing these types of videos. These are really helpful and i think you also get good response from these type of videos. Thank you.

ashutoshmishra
Автор

I find __name__ = __main__ very useful when writing GUI library objects.
It enables you have a little test app in the mod so you can test the lib code without having to import the lib into a host app for testing.
Great for isolating bugs in "imports".

johnnytoobad
Автор

Useful tutorial for us noob python programmers! Thx

ericyip
Автор

Obviously the reverse to that is "if __name__ == "calculator":", which will allow you to run a snippet of code only when a file gets imported, for instance "print("do not import calculator directly; use 'from' instead")".

dirtydevotee
Автор

Yesterday I was thinking about this topic when I watched video

mohammedallauddin
Автор

Wow, I finally understand this shii😂🎉❤

GbolahanAdesina
Автор

Not too useful in an interactive environment where any page (module) can be executed independent of other modules. The __name__ variable is set to __main__ only on start up. In an interactive environment, you first start Python and then you run any number of applications without restarting. Developing code by restarting Python for every task is clunky and while ok for quick and dirty apps, is unacceptably tedious in many "REPL" situations. However, checking for the __main__ value can have its uses and may be very useful for non-interactive users of Python.

carlabest
Автор

😂 wow i I didn’t know that today I learned something

justchecking
Автор

So then the "[if __name__ == '__main__']" is used in the main script of my project or in his modules? Thx for the video!

JonathanDanielAdurian
Автор

Thank you for this easy to understand explanation. Tbh python is not making it easy to work with module exports. I now have a better appreciation for JavaScript's ESM export and import syntaxes.

BeeBeeEight
Автор

Just saw this in class and had to figure out what it was lol.

cloudzero
Автор

Thanks Tim, please can you let me know about a fact : I m a data scientist and as there are no available jobs at the moment, I m asking if I m in danger (should I switch to another domaine)and I would please like you to tell me if data scientist will have a good career in the future or NOT ?
Thank you sir !

drm
Автор

Bro is the only reason I and many others are in tutorial

devanand
Автор

Sir which Operating system you use please reply 🙏

Bharatpremi-fj
Автор

Can you show ius your vs code setting and theme

AnotherLevel
Автор

I KID YOU NOT - when I tell you for THREE years I ALWAYS just look att hat if __name__ statement and say "ONE DAY i will know exactly WHO IN THE DAMNED DEVIL U ARE AND WHT DO U WANT AND WHY U EXIST... but for now my estranged friend I trust the A.I knows better and keeps you here for a reason.. so I too shall accept your company here untill we meet

thebicycleman
Автор

Unfortunately, I totally have ideas about __name__ == "__main__" lol😁😁😁

davidlu
visit shbcf.ru