14. if __name__ == '__main__' [Python 3 Programming Tutorials]

preview_player
Показать описание
The python tutorial guides us about if “ __name__”==”__main__”. It will teach us what is “__name__” in python, how it is executed and how to execute python file from a command prompt.

Topics that are covered in this Python Video:
0:00 Overview
0:17 what is __name__
2:42 Execute python file from a command prompt

Next Video:

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

This Youtuber has long way to go among all Programming Youtubers. Succinct explanations, well edited and to the point videos, awesome fluency. Thanks you sir. after Telusko channel, I really liked your channel among Indian Programming Youtubers.

Vijay-Yarramsetty
Автор

This video is the best one on explaining this topic so far. The instructor has very good communication skills. I did many years of programming. When I learnt this __main__ thing for the first time, I listened to many people. None of them can communicate with the exact point this instructor said. Right to the point!

ming
Автор

For people who are trouble understanding this
__name__ in same file will show __main__
but whenever in other file or module then it prints the module name where that function is actually located.

so over there in area.py it was present so it printed area when running from caller.py
but when running from area.py only then it printed __main__ because same module.

kiyochi
Автор

I appreciate greatly the way you make sure that your code IS READABLE to the video viewers. That is so important in coding tutorials and it is so often neglected. People just use raw screen capture and the coding is almost impossible to make out. Good for you!

jesuisravi
Автор

This has been the best understanding of __name__ I have ever seen. Not to say there are similar ones though. Very good

What_I_Make
Автор

so if you run the program without importing any modules then __name__ == __main__
but if you import a module then __name__ == the name of the file with the module

but why use this?...I could just call the function in the imported module?
I am a beginner so apologies if I sound a little dumb : )

kools
Автор

wow thank you, finally someone who is good at explaining things!

Dabblng
Автор

Hey, nice video 🙌
But I wanted to know what it's use

vipul
Автор

thank you! learned a lot from your videos

rebornbright
Автор

Just posting my understanding: __name__ is a special variable in Python that holds the name of the current module. If the script is being imported as a module into another script, then __name__ is set to the name of the module.

mrharshsr
Автор

It feels like this could be used to check if you're in either your main function or your main python file from where you're running the code? Is this the usual use case? Are there other use cases for getting the value of __name__?

criiptico
Автор

so the area will only be calculated when the you run the module itself
it won't be calculated when the module is imported to another program i.e when __name__ != "__main__:

setfojx
Автор

Good explanation but it didn't calculate the area in the second file, am I missing something?

pasha
Автор

how to access files in Command prompt i cant get it

Alihamuslimahvlogs
Автор

hello sir. could you please tell me which is the best online pycharm compiler which can execute these programs without any error?

tabassumhossain
Автор

i am a beginner and I understand what is happening here in your video BUT why use it?...can you give me any real world examples please?

kools
Автор

but at the end y it didn't print area under caller.py?

shvetarastogi
Автор

Where is exercise of this topic..can't see ..plz guide

harishaziq
Автор

hello sir, i am using ipython notebook.. i am getting problem while importing this module.
i have created caller file in ipython notebbok and in that i imported main file but it is showing error 'ModuleNotFoundError: No module named 'main'.what should i do.
my first is excuting properly.

ganeshgunjal
Автор

bery helpful. thank you for your effort

DervishVNihil
join shbcf.ru