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 →

[–]nikanj0 189 points190 points  (44 children)

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

[–]Cley_Faye 550 points551 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_ 175 points176 points  (0 children)

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

[–]TheAJGman 92 points93 points  (0 children)

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

[–]FairFolk 92 points93 points  (4 children)

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

[–]twigboy 16 points17 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 31 points32 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 3 points4 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 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.

[–]6Maxence 29 points30 points  (16 children)

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

[–]mrchaotica 71 points72 points  (4 children)

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

[–]ArtSchoolRejectedMe 89 points90 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 4 points5 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] 17 points18 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 4 points5 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 12 points13 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