r/ProgrammerHumor 2d ago

Meme pythonFeelsillegal

Post image
6.7k Upvotes

219 comments sorted by

View all comments

1.0k

u/belabacsijolvan 2d ago

theres main() in python

25

u/Candid_Highlight_116 2d 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.

33

u/AliceCode 2d ago

if __name__ == '__main__':