this post was submitted on 03 Jun 2025
490 points (99.0% liked)

Programmer Humor

23795 readers
2687 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] RapidCatLauncher@lemmy.ca 97 points 3 days ago (5 children)

That just gave me the idea that it would be fun to inspect exit a little.

Which led me down this path:

>>> repr(exit)
'Use exit() or Ctrl-Z plus Return to exit'
>>> dir(exit)
[(...), 'eof', 'name']
>>> exit.eof, exit.name
('Ctrl-Z plus Return', 'exit')

Okay, cool, the "Use exit() etc." blurb appears because it's the function's repr, and the string is assembled from its name and eof properties.

Now let's try to make our own:

>>> exit.__class__
<class '_sitebuiltins.Quitter'>
>>> gtfo = exit.__class__()
TypeError: Quitter.__init__() missing 2 required positional arguments: 'name' and 'eof'

Oh Python, you shouldn't have.

>>> gtfo = exit.__class__("a big puff of smoke", "a sneaky skedaddle")
>>> gtfo
Use a big puff of smoke() or a sneaky skedaddle to exit

Beauty!

[–] squaresinger@lemmy.world 1 points 2 days ago (2 children)

Does gtfo() then work as expected?

load more comments (2 replies)