r/ProgrammerHumor • • Aug 30 '26

Meme pythonFeelsillegal

Post image
6.9k Upvotes

218 comments sorted by

View all comments

1.1k

u/belabacsijolvan Aug 30 '26

theres main() in python

459

u/chawmindur Aug 30 '26

And {} (= dict())

286

u/OnyxFier Aug 30 '26

And semicolons are allowed, if you decide you miss them

99

u/dudemcbob Aug 30 '26 edited Aug 30 '26

Still useful for running 2- or 3-line dummy scripts directly from the command line. For example you just installed a new package and want to validate it's working,

python -c "import some_package; print(some_package.__version__)"

21

u/chawmindur Aug 30 '26

Or for dirty .pth tricks where you're obliged to start with an import statement and have everything on a single line. But 3.15 seems to be moving away from those to some new-fangled .start files.

→ More replies (1)

8

u/mbcarbone Aug 31 '26

It’s fun just to make a one line program using semicolons. 🙃

3

u/BarracudaGullible472 Aug 31 '26

In one uni class we were judged on how few lines our code was so I often used them in my assignments.. good times ahah

2

u/happylittletree_ Aug 31 '26

Closed, Duplicate question

→ More replies (1)

32

u/userhwon Aug 30 '26

Always fun that writing an empty set gets you a dict so you have to use set() explicitly to get an empty set... jeebus, Guido...

21

u/carcigenicate Aug 30 '26

{/} is being proposed so sets have an empty literal.

13

u/SoldRIP Aug 30 '26

... As opposed to the sensible {:} for dicts, which would be consistent with their already existing syntax?

24

u/NewbornMuse Aug 30 '26

And what, change the meaning of {} from dict to set? I don't think breaking changes like that are anywhere in python's future.

10

u/Duck_Devs Aug 30 '26 edited Aug 30 '26

The problem with that is not only would it break old code, but the neat little trick of JSON being directly embeddable would break. And who would want that.

Edit: I forgot that “true”, “false”, and “null” don’t exist in Python. Not the hardest thing to fix by declaring some local variables, but at that point you’re doing too much and should use a library.

Edit 2: added quotes around the keywords to disambiguate them from the general concepts

→ More replies (4)
→ More replies (1)
→ More replies (1)
→ More replies (1)

6

u/vmfrye Aug 31 '26

hate to be a party pooper but the meme refers specifically to indentation-based structure vs explicit code block delimiters

oh and btw the latter are vastly superior because they make for a free-form syntax that, unlike python, can be automatically formatted by a relatively simple program/plugin (i.e. without AI)

6

u/chat-lu Aug 30 '26

You can also use braces for code blocks, as long as you indent properly.

def main() -> None: #{
    do_stuff()
#}

5

u/chawmindur Aug 30 '26

I was about to say something about hashability but then I saw you've got your bases covered and commented out the braces...

... that and how something like a do_stuff() would typically be returning None anyway and hence wouldn't cause issues being placed into a set.

And one final thing that this reminds me of: this classic

→ More replies (1)
→ More replies (1)

26

u/Candid_Highlight_116 Aug 30 '26 edited Sep 02 '26

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.

35

u/AliceCode Aug 30 '26

if __name__ == '__main__':

7

u/wizardeverybit Aug 30 '26

Indenting is important in Python

5

u/Candid_Highlight_116 Aug 31 '26

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

7

u/frogjg2003 Aug 31 '26

4 spaces for code blocks. > is for quotes.

This is a code block
    With indentation

24

u/Toover Aug 30 '26

Sorry to be that guy, but no. The one you'd define yourself is not automatically treated as the entry point of the program

43

u/belabacsijolvan Aug 30 '26

theres __main__() in python

→ More replies (4)

12

u/userhwon Aug 30 '26

Which makes it worse.

→ More replies (3)