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.

Thoughts?

Thanks,
Sean
-- 
 Peppermint Patty gets a DSL line in "YOU'D TELL ME IF YOU WERE IN A GERMAN
 SCHEISSE VIDEO WOULDN'T YOU, CHARLIE BROWN"
Sean Reifschneider, Member of Technical Staff <[EMAIL PROTECTED]>
tummy.com, ltd. - Linux Consulting since 1995: Ask me about High Availability

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to