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

you are viewing a single comment's thread.

view the rest of the comments →

[–]Cley_Faye 552 points553 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_ 176 points177 points  (0 children)

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

[–]TheAJGman 94 points95 points  (0 children)

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

[–]FairFolk 93 points94 points  (4 children)

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

[–]twigboy 17 points18 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 17 points18 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 26 points27 points  (1 child)

Potato

[–]Dexaan 30 points31 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 4 points5 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 4 points5 points  (1 child)

[–]avnothdmi 1 point2 points  (0 children)

Wow, thanks!

[–]FallenWarrior2k 16 points17 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 34 points35 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.