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

454

u/chawmindur 2d ago

And {} (= dict())

32

u/userhwon 2d ago

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...

20

u/carcigenicate 2d ago

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

13

u/SoldRIP 2d ago

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

25

u/NewbornMuse 2d ago

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

3

u/minecon1776 1d ago

Python 4

10

u/Duck_Devs 2d ago edited 2d ago

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

2

u/Loading_M_ 2d ago

JSON (or any data format) being directly embeddable sounds nice in theory, but isn't really a great idea in practice.

JSON was originally intended to be loaded via eval. This was exploited almost immediately, which is why JS got proper JSON parsing and serialization functions. You should always run JSON (and any other serialized format) through a proper parser to load it. If you're clever, you can do this at build time, but you should never rely on any data file being valid at runtime.

1

u/Duck_Devs 2d ago

Well yes. I know. I think of Python’s syntax being mostly compatible with JSON as a

> neat little trick.

I actually forgot that eval() was a thing when I wrote that comment.

What I meant was, you could copy and paste your own JSON into your source code for a simple payload in a throwaway script, for whatever you may need it for.

Edit: Reddit mobile app doesn’t want to make that a block quote. You get the idea though.

2

u/Character-Education3 2d ago

true false and None most definitely exist in python

Also any modern text editor will auto complete dict() for you.

What is everyone going on about?

8

u/TheDreadedAndy 2d ago

I think he was talking about directly eval-ing a json string to parse it.

While True, False, and None exist in python, true, false, and null don't. So you'd have to locally define those first.

1

u/JanEric1 1d ago

breaking change unfortunately. Maybe a thing for Python4 which will never come

1

u/JanEric1 1d ago

Is a draft for over a year now and was targeting 3.15. Dont think that makes it?