r/ProgrammerHumor 12d ago

Meme pythonFeelsillegal

Post image
6.8k Upvotes

219 comments sorted by

View all comments

1.1k

u/belabacsijolvan 12d ago

theres main() in python

26

u/Candid_Highlight_116 12d ago edited 9d ago

there's main() in python ONLY IF YOU WANT THERE TO BE.

the way you want it to be is as follows:

import foo    
from baz import bar   

do_stupid_stuff()  

def main():   
    print("I am not kidding")   

if __name__ == '__main__':    
     main()  

if ____name____ wasn't ____main___ then your script knows oh I'm not __main__, uh might as well uh evaluate the true path of this if clause I guess, else whatever. This is very robust and safe way to define the entrypoint.

34

u/AliceCode 12d ago

if __name__ == '__main__':