Stupid Python Tricks: Q is for Quit - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: General (https://python-forum.io/forum-1.html) +--- Forum: Code sharing (https://python-forum.io/forum-5.html) +--- Thread: Stupid Python Tricks: Q is for Quit (/thread-1135.html) |
Stupid Python Tricks: Q is for Quit - ichabod801 - Dec-07-2016 I write a lot of text interfaces, probably because I'm too lazy to write a GUI unless I need one. So I am frequently programming 'q' to quit the program. And I am frequently using 'q' to quit a program. So I frequently use 'q' to quit Python. I decided to fix this deficiency:import sys class Quitter(object): """ Quit on q. (object) Overridden Methods: __repr__ """ def __repr__(self): """Quit on q. (None)""" sys.exit() q = Quitter()Usage: craig@craig-Latitude-E5440:~/Documents/Python$ python3 Python 3.5.2 (default, Nov 17 2016, 17:05:23) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> q craig@craig-Latitude-E5440:~/Documents/Python$ RE: Stupid Python Tricks: Q is for Quit - Mekire - Dec-07-2016 Overriding reprint for nefarious purposes. That's fun. |