Why You Should Use Python if __name__ == "__main__"

Поделиться
HTML-код
  • Опубликовано: 27 сен 2024

Комментарии • 75

  • @k0nze_builds
    @k0nze_builds  2 года назад +2

    Get your FREE Python Cheat Sheets: k0nze.gumroad.com

  • @OZTutoh
    @OZTutoh 2 месяца назад

    As a python beginner in 2024, I say thank you for this tutorial. There are so many wack articles out there trying to explain 'if __name__ == "__main__":'.
    I rewound the video a few times but I understand it now.

  • @ilshatabdulmanov2140
    @ilshatabdulmanov2140 2 года назад +4

    I've been struggling with this notion of __name__ == "__main__"
    for a long time.
    Thanks a lot for a clear and concise explanation !

  • @ekarata.361
    @ekarata.361 2 года назад +2

    After watching multiple videos explaining this concept, I finally understand it from you. Thanks!

  • @clintwestwood4545
    @clintwestwood4545 2 года назад +5

    Only video I understood on this matter. You have the skills of a true teacher. Also, the scenery is lovely. Nice nature background :D

  • @amitkoushik5504
    @amitkoushik5504 Год назад +12

    To the point explanation.... always ignore why it's written in python but now you cleared that. Keep making such high quality content ❤

  • @moyz2469
    @moyz2469 2 года назад +2

    Awesome video K0nze! Excellent explanation!

  • @apple_vlogs10
    @apple_vlogs10 Год назад

    before this video i went through 3-4 tutorials to understand this point , it got cleared in your video
    great explanation !!

  • @tw9535
    @tw9535 Год назад

    I have watched several videos on this subject. Yours is the very best.
    Thank you!

  • @Ren-io4sx
    @Ren-io4sx 2 года назад +1

    only comprehensive explanation out there!

    • @kools67
      @kools67 2 года назад

      it was a very good explanation - especially when it ran both codes after the import - you can see what is clearly happening and why you need a 'guard', as he says...I am soo happy that i understand this now and I can carry on with my python learning : )

  • @femi2873
    @femi2873 Год назад

    thanks, i watched other videos on this topic, but your video was the best and i was able to clearly understand the concept you were explaining

  • @prakashgadupoodi7549
    @prakashgadupoodi7549 Год назад

    Clean, Clear and Crisp. Million thanks for the great video!

  • @chuckwm
    @chuckwm Год назад

    🖥Great explanation.

  • @jonhanson8925
    @jonhanson8925 Год назад

    Wow! I finally know! Thanks for the explanation! 🖥

  • @education.online_frevryone
    @education.online_frevryone Год назад +1

    Understood

  • @iamdedlok
    @iamdedlok 2 года назад

    🖥watched till the end :) haha thanks for the nice explanation!

  • @andrecruzrodrigues5157
    @andrecruzrodrigues5157 2 года назад

    best explanation ever after lots of videos. GJ bro! thanks 🖥

  • @LexOnTheWeb
    @LexOnTheWeb Год назад

    🖥️ Thanks for the explanation!

  • @ironmonkey1990
    @ironmonkey1990 17 дней назад

    thank you!

  • @jossec1344
    @jossec1344 7 месяцев назад

    thank you mate

  • @sarkhanmammadli9673
    @sarkhanmammadli9673 Год назад

    thank you for the clear explanation!

  • @kristinamwangekan2471
    @kristinamwangekan2471 Год назад

    Thank you

  • @giladharnik2499
    @giladharnik2499 Год назад

    Great video! Thanks 🖥️

  • @STYX1966
    @STYX1966 Год назад

    🖥Thank's. Now I get it!

  • @peytonmulder8059
    @peytonmulder8059 5 месяцев назад

    I feel silly, I just asked this question on the previous video I watched 🤣 🖥

  • @rajatpathak4499
    @rajatpathak4499 4 месяца назад

    brilliant

  • @minhly650
    @minhly650 2 года назад +1

    So what is the difference between two following code if I just execute them as script alone?
    def greeting():
    print('Hello World!')
    greeting()
    and
    def greeting():
    print('Hello World!')
    if __name__ == "__main__":
    greeting()
    Thanks

    • @kychemclass5850
      @kychemclass5850 2 года назад

      No difference - if all you're running is that code at once (i.e. from one python file or manually entered at the command line). The file that's initially run and pulls modules/libraries into it is decreed as __main__. so each version of your code will be __main__.

  • @MunirLoyed
    @MunirLoyed Год назад

    So simply it means don't run imported code unless it is called.

  • @yoyaaaa4111
    @yoyaaaa4111 Год назад

    Thank you👍

  • @runner6994
    @runner6994 Год назад

    Great explanation. I get it. c💻

  • @harispilton5614
    @harispilton5614 6 месяцев назад

    Hi, I like to buy your cheat sheets but via Pay Pall. Is this possible?

  • @ioannismesionis6639
    @ioannismesionis6639 2 года назад

    Great video! How did you format the terminal showing this arrow-like format for your path?

  • @jyothikrishnanshenbagamoor4093
    @jyothikrishnanshenbagamoor4093 6 дней назад

    ❤❤❤

  • @Medx111
    @Medx111 2 года назад

    Keep it up

  • @DIGmbl
    @DIGmbl 7 месяцев назад

    Why not "dunder"? Instead of "underscore, underscore"?
    At least it is faster.

  • @RaftxoWysocki
    @RaftxoWysocki Год назад

    Is there a way to avoid executing my_module code without editing it adding if __name__=="__main__" ?
    🖥🖥👍

  • @kychemclass5850
    @kychemclass5850 2 года назад

    WHERE do you add it? At the bottom after functions or at the top? (requires indenting all the time)

    • @kools67
      @kools67 2 года назад +2

      i think you add it to the start of the programme where it needs to begin - so after you have set up your functions or imported any modules add it after those - i hope i am correct : )

    • @kychemclass5850
      @kychemclass5850 2 года назад

      @@kools67 Tq

  • @VenkateshGowdSomasamudram
    @VenkateshGowdSomasamudram Год назад

    🖥

  • @a-man-lol
    @a-man-lol 2 года назад

    good video (computer emoji)

  • @education.online_frevryone
    @education.online_frevryone Год назад

    💻

  • @Mooodf
    @Mooodf Год назад

    bester mann

  • @stevenjoyner903
    @stevenjoyner903 Год назад

    STEVEN BRIAN JOYNER

  • @si0p
    @si0p 2 года назад

    I have one question if the developer doesnot use if __name__=='__main__' statement while making my_module.py then either you add if __name__=='__main__' in main_script.py or not add , it will not work as you said.
    So developer must have to use the above statement so that we can use module and got expected resutl.
    So, again question is that if developer has already used the above statement in my_module.py then why should we use that statement again in main_script.py. As we know using it in main_script.py doesnot make any sense. CORRECT ME IF I AM WRONG because your example didnot completely made the sense.
    ----------------my_module.py-------------------
    def abc(a,b):
    return a+b
    print('hello')
    ---------------main_script.py--------------
    import my_module
    if __name__=='__main__' :
    print(test.abc(5,4))
    NOTE: I think we actually add that statement in main_script.py because we make our own function before starting if __name__ == '__main__' statement in main_script.py. So I think we do so inorder to use that main_script.py as module in future.

  • @nutinmyass
    @nutinmyass 8 месяцев назад

    In my case I want code in the module to run when it’s imported, so I don’t use this.
    Is that valid, or does that mean I’m making a poor design choice somewhere?

    • @k0nze_builds
      @k0nze_builds  8 месяцев назад

      If your module is not runnable standalone, you don't need to add it.

  • @emperor8716
    @emperor8716 8 месяцев назад

    So basically: code in this block will only run if you run that file directly. explained in 1 sentence.

  • @breemudi
    @breemudi Год назад

    🖥

  • @TilenKow
    @TilenKow 2 года назад

    💻

  • @kools67
    @kools67 2 года назад +2

    great video K0nze!! - by showing us what happens with the two codes running after the import, you made me understand and why you need a 'guard' to block off other lines of codes running in the imported module - well done!!

  • @Marcusram
    @Marcusram Год назад

    Thanks! I finally understand this disgrace 😅

  • @alirezafazeli231
    @alirezafazeli231 21 день назад

    Thanks

  • @strade740
    @strade740 10 месяцев назад

    💻🖥bro u are great

  • @eisbar2polar246
    @eisbar2polar246 Год назад

    🙃

  • @LifeOf97
    @LifeOf97 Год назад

    🖥️

  • @matiasmatu_tdf6837
    @matiasmatu_tdf6837 Год назад

    ty. Excelent

  • @antonywmiller
    @antonywmiller 2 года назад

    🖥 thanks

  • @ranjanthapa3964
    @ranjanthapa3964 2 года назад +1

    well explain, thank you🙂🙂

  • @fidi7400
    @fidi7400 Год назад

    Thanks so much for this video, I spent hours trying to understand the main method from other resources and could not get it until now!

  • @lemonade1960
    @lemonade1960 Год назад

    🖥

  • @sherwinantony3512
    @sherwinantony3512 2 года назад

    🖥

  • @jakubwilgocki319
    @jakubwilgocki319 2 года назад

    🖥

  • @moyz2469
    @moyz2469 2 года назад +1

    🖥

  • @Sherloklol
    @Sherloklol Год назад

    i can see clearly now... the confusion is gone...ty!

  • @shakhzod8583
    @shakhzod8583 Год назад

    🖥 Wonderful video) Thank you very much !

  • @alexbecks5199
    @alexbecks5199 Год назад

    Straight to the point! Thanks 👍🏽 🖥

  • @3DCrafterBro
    @3DCrafterBro 2 года назад

    thanks man :)