A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2006-April/064240.html below:

[Python-Dev] Builtin exit, good in interpreter, bad in code.

[Python-Dev] Builtin exit, good in interpreter, bad in code.Crutcher Dunnavant crutcher at gmail.com
Mon Apr 24 04:12:31 CEST 2006
On 4/23/06, Sean Reifschneider <jafo-python-dev at tummy.com> wrote:
> A friend of mine is learning Python, and had a problem with the exit
> builtin.  I like that in the interpreter it gives useful information, but
> he was writing a program in a file and tried "exit(0)", and was presented
> with the non-obvious error:
>
>    TypeError: 'str' object is not callable
>
> What about something like:
>
>    >>> class ExitClass:
>    ...    def __repr__(self):
>    ...       return('Hey, press control-D')
>    ...    def __call__(self, value):
>    ...       raise SyntaxError, 'You want to use sys.exit'
>    ...
>    >>> exit = ExitClass()
>    >>> exit
>    Hey, press control-D
>    >>> exit(1)
>    Traceback (most recent call last):
>      File "<stdin>", line 1, in ?
>      File "<stdin>", line 5, in __call__
>    SyntaxError: You want to use sys.exit
>
> Jerub on #python thinks that maybe it needs to subclass the string object
> instead, but in general it seems like it might be an improvement.

Why don't we just not define 'exit' in non-interactive environments?

--
Crutcher Dunnavant <crutcher at gmail.com>
littlelanguages.com
monket.samedi-studios.com
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4