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

26

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.

6

u/wizardeverybit 2d ago

Indenting is important in Python

5

u/Candid_Highlight_116 2d ago

I fought and gave up Reddit markdown, should have used spaces after newline not quote sorry

7

u/frogjg2003 2d ago

4 spaces for code blocks. > is for quotes.

This is a code block
    With indentation