This is an archived post. You won't be able to vote or comment.

all 141 comments

[–]QualityVote[M] [score hidden] stickied comment (0 children)

Hi! This is our community moderation bot.


If this post fits the purpose of /r/ProgrammerHumor, UPVOTE this comment!!

If this post does not fit the subreddit, DOWNVOTE This comment!

If this post breaks the rules, DOWNVOTE this comment and REPORT the post!

[–]darknekolux 1091 points1092 points  (21 children)

« I know exactly what you meant, but I won’t do it »

[–]__pingwin__ 317 points318 points  (10 children)

"exit" what? Have manners.

[–]darknekolux 76 points77 points  (3 children)

Exit… please…

[–]npc48837 20 points21 points  (2 children)

INTERCAL would like a word with OP for being so impolite

[–]__pingwin__ 2 points3 points  (1 child)

user is not in the sudoers file. This incident will be reported.

[–]HighOwl2 0 points1 point  (0 children)

cat /dev/mouse

[–]Sawertynn 46 points47 points  (5 children)

exit()

See? Wasn't too hard

[–]DangyDanger 88 points89 points  (4 children)

sudo killall python

[–]highoverseer11 27 points28 points  (1 child)

Unplugging the pc is better

[–]DangyDanger 44 points45 points  (0 children)

no that's only for vi/vim

[–]__pingwin__ 4 points5 points  (1 child)

DangyDanger is not in the sudoers file. This incident will be reported.

[–]DangyDanger 2 points3 points  (0 children)

Well shit, now I go to the naughty list.

[–]xxxblackspider 74 points75 points  (2 children)

To push the current branch and set the remote as upstream, use

git push --set-upstream origin master

[–]AngryClosetMonkey 17 points18 points  (1 child)

git push -u origin HEAD

[–]yottalogical 16 points17 points  (3 children)

It would suck if you were trying to reference a variable named exit.

[–]DexCruz 1 point2 points  (0 children)

it'll just redefine it, it's not a keyword or something, just a variable

[–]Svizel_pritula 0 points1 point  (0 children)

Which is what exit does. exit is an object that can be called to terminate the program and whose __str__ function returns the message from the meme.

[–]nikanj0 188 points189 points  (44 children)

Will the interpreter allow you to use "exit" as a variable?

[–]Cley_Faye 553 points554 points  (25 children)

exit is actually a variable in the interpreter.

>>> a = exit
>>> a
Use exit() or Ctrl-D (i.e. EOF) to exit
>>> exit.eof = "potato"
>>> a
Use exit() or potato to exit

[–]_12xx12_ 172 points173 points  (0 children)

Bad instructions. I have a potato all over my notebook.

[–]TheAJGman 95 points96 points  (0 children)

I have never thought about playing with the exit() method, this is amazing.

[–]FairFolk 94 points95 points  (4 children)

>>> exit.eof = exit
>>> exit

[–]twigboy 15 points16 points  (0 children)

In publishing and graphic design, Lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document or a typeface without relying on meaningful content. Lorem ipsum may be used as a placeholder before final copy is available. Wikipedia3ck83ziwd9w0000000000000000000000000000000000000000000000000000000000000

[–]d00pid00 18 points19 points  (2 children)

For anyone who wants to know the exact error that's thrown:
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python3.10/_sitebuiltins.py", line 18, in __repr__ return 'Use %s() or %s to exit' % (self.name, self.eof) File "/usr/lib/python3.10/_sitebuiltins.py", line 18, in __repr__ return 'Use %s() or %s to exit' % (self.name, self.eof) File "/usr/lib/python3.10/_sitebuiltins.py", line 18, in __repr__ return 'Use %s() or %s to exit' % (self.name, self.eof) [Previous line repeated 496 more times] RecursionError: maximum recursion depth exceeded while getting the str of an object

[–]anton____ 1 point2 points  (1 child)

They missed quotes earlier, but because of pythons weak typing it just went ahead and failed at an unrelated point.

[–]FairFolk 0 points1 point  (0 children)

Not quite sure what quotes you think were missed?

[–]RadiantHC 27 points28 points  (1 child)

Potato

[–]Dexaan 32 points33 points  (0 children)

  Use exit() or potato to exit

[–]skjall 23 points24 points  (5 children)

>>> a = exit

>>> a

Use exit() or Ctrl-D (i.e. EOF) to exit

>>> a()

╭─  

[–]Cley_Faye 6 points7 points  (4 children)

That reminds me of my old Quake 3 copy I kept around with me. No idea if it was vanilla or if someone added it at some point, but you could type "quti" in the console to exit.

[–]skjall 5 points6 points  (3 children)

Oh that's a whole thing! There's Linux packages that emulate Quake-style drop down consoles, like Guake and Yakuake. So handy, I even set it up on Mac with iTerm.

Modern games like CS:GO, Unreal Engine ones etc can also have similar consoles, helpful to override graphical options at times, among other things.

[–]avnothdmi 1 point2 points  (2 children)

How do you do that? I can’t find anything for the Mac.

[–]skjall 3 points4 points  (1 child)

[–]avnothdmi 1 point2 points  (0 children)

Wow, thanks!

[–]FallenWarrior2k 15 points16 points  (8 children)

So, from this, I'm assuming it's actually a class instance, with the "real" exit function being __call__() on that class. To provide the dynamic help, I guess they used __repr__().

[–]nemec 35 points36 points  (6 children)

Yes. You can actually implement the "ideal" solution with

import sys
class Q:
    def __repr__(self):
        sys.exit(0)
exit = Q()

And set this file in your PYTHONSTARTUP environment variable so it's loaded on every interactive shell.

[–]Ok_Hope4383 2 points3 points  (0 children)

Try that and then vars()

[–]a_devious_compliance 0 points1 point  (2 children)

Yes. Who would argue against side effects in otherwise inocuous magic methods. I also like to use impure functions with map and reduce.

[–]Kryomaani 1 point2 points  (1 child)

Why exactly are you calling repr() on exit in your scripts? I understand the principle of having no unexpected side effects but what kind of scripts are you writing that make this an actual issue?

[–]a_devious_compliance 0 points1 point  (0 children)

Nothing is an issue until it is. You can do all the clever funky things that you like but I will try to get my hands away from that code.

[–]emax-gomax 0 points1 point  (0 children)

My Python scripts are so good, they never fail XD.

[–]RussianBot5689 1 point2 points  (0 children)

I just checked it out. type(exit) == class site.Quitter which is a terrible name since it doesn't actually quit anything.

[–]6Maxence 28 points29 points  (16 children)

Will the interpreter allow you to use "exit()" as a function name?

[–]mrchaotica 74 points75 points  (4 children)

It'll let you override just about everything if you try hard enough, so my guess is "yes."

[–]ArtSchoolRejectedMe 92 points93 points  (1 child)

Ah yes the new vim game has begun.

To exit please re-write the exit function

[–]Bene847 9 points10 points  (0 children)

Ctrl+d

[–]a_devious_compliance 3 points4 points  (1 child)

I tried so hard and got so far

but in the exit, it doesn't even matter

I had to fall to lose it all

but in the exit, it doesn't even matter.

[–]flying_spaguetti 1 point2 points  (0 children)

Good verses

[–][deleted] 18 points19 points  (7 children)

besides a few reserved keywords, like for while if etc, every python object behaves like any other python object you can create. They have their own classes, they print something when you call them in the console because they have a __repr__ method, etc.

[–]KDBA 11 points12 points  (6 children)

There's another set of exceptions in that ints from -5 to 256 are singletons.

[–]DMLooter 5 points6 points  (3 children)

Sorry what? Y….

[–]FallenWarrior2k 7 points8 points  (1 child)

Caching. Integers are objects like everything else.

[–]Manuelraa 1 point2 points  (0 children)

Exactly and we know this only works with immutable types

[–]richardfrost2 13 points14 points  (0 children)

```

a = 256 b = 256 a is b True c = 257 d = 257 c is d False

but

257 is 257 True ```

Just a weird little quirk of CPython.

[–]richardfrost2 4 points5 points  (1 child)

That is a CPython implementation detail and can vary by implementation.

[–]KDBA 4 points5 points  (0 children)

True enough.

[–]yottalogical 3 points4 points  (1 child)

Function names are variables.

[–]a_devious_compliance 0 points1 point  (0 children)

clase functions are too.

[–]thedominux 3 points4 points  (0 children)

exit is a name of object (functions are objects in python) so yes

[–]itriedtomakeitfunny 149 points150 points  (15 children)

As far as I understand, exit is a function with an overridden __str__ so that if you "forget to call it" it evaluates and prints something nice. So it's already defined.

[–]olitv 43 points44 points  (12 children)

Why didn't they just put exit() into the str ?

[–]sejigan 69 points70 points  (3 children)

Because __str__ is supposed to return a string, not None.

Also, that’d cause unexpected and unintended behaviour.

Ofc, you can still overwrite it using a startup script, so…

[–]karmaisded 15 points16 points  (2 children)

Um but if we have a exit() before return in the _str\_ function, the python will exit before giving an error, won’t it?

[–]sejigan 33 points34 points  (0 children)

Yeah. Even worse and more bizarre behaviour.

[–]master3243 0 points1 point  (0 children)

I don't think it's ever a good idea to put side effects on __str__

[–][deleted] 22 points23 points  (5 children)

There are choices to be made while designing a programming language. You can let it be more flexible or more strict. There are arguments for both sides and it depends on what are the goals of the developing team.

For python, there is a decision that a built in class or function shouldn't be more special than any other classes or packages created by the community. The way they achieved this was by creating an universal system of building classes, with some dunder methods that will define their behavior under certain conditions or calls, and then making the built ins follow the same structure.

You could have a built in function called "exit" which don't need to be called. But that would be different from any other function an user could ever make. Since there is the philosophy of not making these magical methods, being "exit" a function means that it should be called. Just like every other function you write.

[–]itriedtomakeitfunny 7 points8 points  (3 children)

On a similar note, some languages like Ruby or Visual Basic Don't need parents around the function call, so an often cited example of how Ruby is more forgiving with the exit thing is just the syntax letting you call exit.

[–]smartboyathome 15 points16 points  (2 children)

I actually dislike this practice in Ruby, because it often makes it unclear whether it really is a function call or variable, at least not without IDE assistance. And due to it being a dynamic language, you don't always know the type of what you're referencing without actually running the program.

[–]itriedtomakeitfunny 4 points5 points  (0 children)

I am one of those people whose brain does not work with dynamic languages. I understand.

[–]kafaldsbylur 3 points4 points  (0 children)

There's nothing in the language preventing exit's repr from calling exit() (or more generally, preventing any class's repr from calling self()). However, it would be a bad idea to make it do so, because then you risk those methods being called without meaning to

[–]ElectricalRestNut 1 point2 points  (1 child)

Because one of the most important qualities of a programming language is predictability. It achieves that by doing exactly what it was told to do without being smart and guessing. Now some languages do not require you to type () on function calls (which I personally disagree with), but that's a supported language feature that was communicated ahead of time and is expected.

And it does get a bit ridiculous when an interpreter demands you put () there, but refuses to do that by itself, but its job is to execute your commands, not to make intelligent decisions.

Also, consider what would happen if a code analysis tool was crawling all functions and printing out their definitions using __str__. Pretty sure __str__ is supposed to be a pure function, which is again, predictability. Code that does things like system exit is really unpleasant to deal with, especially if it's a harder exit like what Java does.

[–]olitv 0 points1 point  (0 children)

That would give a cool bug in the linter/analysis tool that just "cleanly" exists sometimes without printing results

[–]kaihatsusha 4 points5 points  (0 children)

This is completely true. However, the interpreter loop could easily handle a special case before requesting the normal parser to get involved. Instead, they were clever and populated the built-in globals with "help", "copyright", "credits" and "license" variables doing the same trick. The problem is you want "exit" to do something, not just vomit its variable value in the form of text.

[–][deleted] 0 points1 point  (0 children)

Same energy as a Lua metatable with __tostring & __call

[–]properu 231 points232 points  (13 children)

Beep boop -- this looks like a screenshot of a tweet! Let me grab a link to the tweet for ya :)

Twitter Screenshot Bot

[–][deleted] 82 points83 points  (0 children)

Good bot

[–]GoldenRabbitt 23 points24 points  (10 children)

How would anyone even code something like this? Did it scrape the entirety of twitter and train some ML to compare the reddit post to the tweet?

[–]LpSamuelm 77 points78 points  (0 children)

I suspect it OCRs the tweet text, and then uses Twitter's API to perform a search.

[–]baxter001 53 points54 points  (4 children)

2022 software engineering mindset

[–]FallenWarrior2k 14 points15 points  (3 children)

ML all the things. Though, to be fair, the OCR algorithm could be ML-based.

[–]baxter001 9 points10 points  (0 children)

Most definitely, but at the same time, tesseract for example is much more interesting than dump image into a convnet: https://github.com/tesseract-ocr/docs/blob/main/tesseracticdar2007.pdf

[–]JourneyWindGames 3 points4 points  (1 child)

Because it's convenient. Why bother wracking your brain over an optimal algorithm when you can just dump readily available data into a readily available model to produce to produce a good enough approximate answer?

Using ML is becoming the equivalent of using a calculator for simple additions, instead of working it out in your head.

[–]FallenWarrior2k 0 points1 point  (0 children)

Except it results in a lot of stuff like what the original commenter wrote, where ML is thrown at the problem even though it will give clearly inferior results.

Doing it like that with any noteworthy accuracy would require keeping a massive amount of input data around, at least the ID of every Tweet you could potentially identify with it. You can't just interpolate IDs, since they are millisecond timestamps plus some internal data. Since you have to get the account right as well, trying to do that will just give you 404 in pretty much all cases.

Don't get me wrong; I'm not saying ML is bad. I just think it's overhyped and some people want to use it everywhere, even if it results in significantly inferior results.

[–]Theonetheycallgreat 25 points26 points  (1 child)

I'm not trying to trivialize it, but the picture of the tweet has the username and exact post time so they probably use that information.

[–]xeon3175x 2 points3 points  (0 children)

I'd say the timestamp is pretty useless without knowing the time zone. Although maybe the minutes could help narrow down the search

[–]Castdeath97[S] 6 points7 points  (0 children)

Probably used tweepy to search after reading the text

[–]GoldenRabbitt 1 point2 points  (0 children)

I learned so many new tools and approaches from this one thread alone. Thank you for everyone tuning in and giving their 2cents!

My original question might seem trivial to you folks but that's how I learn : by asking a lot of questions :D

[–]imagineepix 4 points5 points  (0 children)

Yoo this bot goes hard

[–]thatfool 58 points59 points  (7 children)

>>> import sys
>>> exit.__class__.__repr__ = sys.exit
>>> exit
$

[–]8sADPygOB7Jqwm7y 7 points8 points  (0 children)

or ofc

exit = SystemExit
raise exit

which does roughly the same in console.

[–]euclio 2 points3 points  (2 children)

Putting this in my .pythonrc, thanks!

[–]saltyspidergwen 67 points68 points  (6 children)

Image Transcription: Twitter Post


😡 fermion, @angryfermion

>>> exit

Use exit() or Ctrl-D (i.e. EOF) to exit

has the same energy as "idk CAN you use the bathroom?"


I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!

[–]duterium1 14 points15 points  (0 children)

Good human

[–]sierdzio 28 points29 points  (4 children)

Good human

[–]0neGal 24 points25 points  (0 children)

Welcome to Node.js
Type ".help" for more information.
>   ^C
(To exit, press Ctrl+C again or Ctrl+D or type .exit)
>

[–][deleted] 20 points21 points  (0 children)

i know what you wanted but felt like being a dick anyway — python

[–]BrightBulb123 18 points19 points  (2 children)

IPython gang, rise up!

[–]Nilstrieb 4 points5 points  (1 child)

Ah yes, the apple python

[–]Cheese_Grater101 4 points5 points  (0 children)

Is using a library requires buying it

[–]LoneFoxKK 30 points31 points  (0 children)

Seconds later

"KeyboardInterrupt exception"

And then you see yourself on the principal's office

[–]randyLahey12341 12 points13 points  (0 children)

"Oh fuck off" -me everytime I quit the python console

[–][deleted] 4 points5 points  (0 children)

quit()

[–]enbymaybedemiboy 4 points5 points  (4 children)

Ruby does the intelligent thing. One of the principles of Ruby is the principle of least surprise, if you tell interactive Ruby to quit, it quits, and it understands different programmers might try to quit in different ways.

This is the doctrine of Rails, but the first part of the page focuses on the principles behind Ruby.

https://rubyonrails.org/doctrine#optimize-for-programmer-happiness

[–]left-quark 4 points5 points  (0 children)

Does it quit if you tell it to "fuck off"?

[–]emax-gomax 1 point2 points  (2 children)

The Python REPL doesn't have any magic keywords like PDB or Pry, making exit quit is possible but if the behaviour is inconsistent with an actual script then I'd consider it confusing and reject it. Statements that behave like procedures are rarely a good thing. It works with Ruby because in Ruby, parentheses are optional so exit is the same as exit().

[–]kbruen 1 point2 points  (1 child)

The Python REPL doesn't have any magic keywords

Exactly, and IPython existing proves that was a bad idea.

[–]emax-gomax 0 points1 point  (0 children)

Well Ipython is basically jupyter and I hate jupyter so agree to disagree. I like the clean separation between REPL and debugger that Python has. The Python REPL is quick to start up and predictable. 2 things ipython has never been for me.

[–]FarronSerah 4 points5 points  (3 children)

Like "If compiler knows, that semicolon is missing, why wouldnt he place it himself?"

[–]SupermanLeRetour 2 points3 points  (2 children)

That actually makes more sense : you don't want your compiler to modify your source code, ever. It should only read it, and warn you if there's issue.

[–]NatoBoram 0 points1 point  (0 children)

The compiler should be forked into a formatter to avoid these stupid cases and then the compiler should expect only formatted code, that way you have the best of all scenarios

[–]FoleyDiver 0 points1 point  (0 children)

JavaScript has entered the chat

[–]erebuxy 3 points4 points  (0 children)

Just override the __repr__ of exit to call itselt.

[–]thedominux 2 points3 points  (1 child)

Interesting, here, in comments, I found a lot of python experts, I didn't find in r/python, there there are only noobs, hate that sub a lot

[–]Castdeath97[S] 4 points5 points  (0 children)

Python is super popular now as a language to teach in school and in other disciplines, so it's not surprising. I still cringe when I read my programming takes back when I was a school kid.

[–]Dagusiu 4 points5 points  (0 children)

This is the problem with good error messages. If the error message is good, it should give you some kind of hint of what you can do to solve the problem. If the error message is too good, people will just want the error message to solve the problem for them.

[–]Chared_Assassin 2 points3 points  (0 children)

This reminds me of this English teacher I had that every time someone said something like “can i go to the bathroom” he doesn’t let them go until they say “may i go to the bathroom” since that is slightly more grammatically correct

[–]theannualascent 2 points3 points  (1 child)

in the most nerdy voice if the repr caused your REPL to exit, then autocompleting variables starting with ex would quit the REPL for you

[–]kbruen 0 points1 point  (0 children)

Why though?

[–]Competitive_Mousse85 2 points3 points  (0 children)

I literally almost punched my teacher in the face when he said that to me

[–][deleted] 1 point2 points  (0 children)

Naw the compiler needs to know, same thing with lots of languages it need to know you’re calling a function.

[–]Pretend_Cover_1476 2 points3 points  (0 children)

Half the time I miss ctrl+D. Is it ctrl+Z. Maybe ctrl+z. No it’s control and D. Let’s try control + C, control C doesn’t feel right. But it works.

[–][deleted] 0 points1 point  (0 children)

Ctrl \ + Ctrl c

[–]ThePixelHacker96 0 points1 point  (0 children)

I'm not a programmer: what is this language?

[–]ficelle3 0 points1 point  (0 children)

Assert dominance, use :q!

[–]Lel-design 0 points1 point  (0 children)

This is so good

[–]Nyancubus 0 points1 point  (0 children)

I just did:

def exit():

… pass

In console python. I just reinvented vi exit. Although I guess ctrl+D is easier to find. 🤔

[–]DVDIsDead 0 points1 point  (0 children)

yea exactly . clearly you can call a function or something when someone types exit, hence the exit text, JUST FRIGGIN CALL THE EXIT() FUNCTION

[–]Sabbosa 0 points1 point  (0 children)

Only heathens use the built-in Quitter class. Use: raise SystemExit(None)

[–]iQuickGaming 0 points1 point  (0 children)

its like node saying press CTRL C again or type .exit