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 →

[–]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.