[Tutor] sys.exit help
evert.rol at gmail.com
Mon Aug 2 22:48:36 CEST 2010
(replying to the full list; hope that was intended.)
>>> I was wondering how can I change sys.exit so if you use command line to run the program. it prompts a message asking if the user wants to exit instead of automatically just exiting?
>> Just write a wrapper exit() function around sys.exit that does that.
> In a post 2 minutes after yours, Steven D'Aprano says, "write your own
> quit() function that
> asks the user and then calls sys.exit if they say yes."
> Is that an example of what you meant by a wrapper? I've never been
> sure I understood the term, "wrapper".
Yes. A "wrapper function" would be a function that "wraps itself around" something else, most of the time around another function. It's often used to expand original functionality of a function, or to make life easier it you need to always set some variables before calling the original function.
In Python, you could almost call it a decorator, although in this case that wouldn't be a good idea. And wrapper function (as far as I'm aware) is a more general term.
For fun I just Googled for "wrapper function" (always useful). First hit leads to wikipedia: http://en.wikipedia.org/wiki/Wrapper_function (though it's a short wiki entry, and I'm not sure how much extra it would clarify).
More information about the Tutor