News for hackers. Stuff that matters.
Re:Curing Python's Neglect by petercooper on Friday May 29, 2009 @10:08PM (#633170)

  >>> exit
  Use exit() or Ctrl-D (i.e. EOF) to exit
Enough said. If you bloody well knew what I typed, just exit FFS.

Python's design is full of shortsighted, dogmatic decisions like this - don't even get me started with functions versus methods and __len__-esque line noise, argggg! And there should only be one obvious way to do something? Give us a break - that's just not how life, mathematics, or anything should work.

Re:Curing Python's Neglect by jjames on Saturday May 30, 2009 @01:58AM (#633311)
Explicit function calling via () is one of my favorite things in the language. To each their own.

"exit" merely references a function. It doesn't call by name alone. It can thus be passed to a function (a callback for example), saved to a variable, etc for later calling. Maybe not so useful for the exit function in the interactive shell but very useful for functional programming. This is an example of consistency, sometimes at the expense of convenience; not great for hacking, awesome for collaboration and large projects (imo).

>>> dir(exit)

['__call__', '__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__', 'name']

(pardon the dunderware)

Here's another way to exit the interactive shell ;)

>>> exit.__call__()

Re:Curing Python's Neglect by derefr on Saturday May 30, 2009 @03:28AM (#633370)
But how does "exit" by itself print that pretty little message telling you that, although it's obvious you wanted to exit, it's not going to let you? It's not just a function reference if it shows up that way.
Re:Curing Python's Neglect by anuraggoel on Saturday May 30, 2009 @04:14AM (#633414)
http://docs.python.org/library/constants.html#exit

In CPython, exit is actually an object of type site.Quitter (the actual class is implementation dependent). site.Quitter overrides the __repr__ special method (which is called by the interpreter on any expression typed in the shell to print the result). site.Quitter also overrides the __call__ special method, so when an object of type site.Quitter is called, the overridden __call__ method invokes system exit.

   >>> exit_class = type(exit) #gets a reference to the class
   >>> my_exit = exit_class('bye') #the arg is used to print the message
   >>> my_exit
   Use bye() or Ctrl-D (i.e. EOF) to exit
   >>> my_exit()
   <python shell exits>
Minor inconsistency: typing "bye()" doesn't work so technically the message is incorrect. But I suppose they don't want you to be hacking exit() in the first place.
Re:Curing Python's Neglect by ii on Saturday May 30, 2009 @06:15AM (#633487)

  >>> class ExitFunc:
  ...   def __call__(self): __builtins__.exit()
  ...   def __repr__(self): return "That's how!"
  ...
  >>> exit = ExitFunc()
  >>> exit
  That's how!
  >>> exit()
Re:Curing Python's Neglect by shiranaihito on Saturday May 30, 2009 @01:39PM (#633888)
"exit" merely references a function. It doesn't call by name alone.

His point was that the user already typed in "exit", and the interpreter recognized the user's intent to exit, so it should just shut up and exit already, instead of telling the user to exit in a different way.

Re:Curing Python's Neglect by martey on Saturday May 30, 2009 @01:07AM (#633276)
The only reason I could think of this warning (which I have run across entirely too many times) was in case someone had a variable called 'exit'. Yet:

  >>> exit = True
  >>> exit
  True
  >>> exit()
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  TypeError: 'bool' object is not callable
The only way to then exit is Ctrl-D, but the shell will not prompt you to enter it!
Re:Curing Python's Neglect by ii on Saturday May 30, 2009 @02:17AM (#633331)
> The only way to then exit is Ctrl-D

Nope.

  >>> __builtins__.exit()
Re:Curing Python's Neglect by ciupicri on Saturday May 30, 2009 @07:40AM (#633537)
Or Ctrl-Z (EOF) on Windows.
Re:Curing Python's Neglect by j2d2 on Saturday May 30, 2009 @12:55AM (#633262)
What makes you think programming languages should mimic life?
Re:Curing Python's Neglect by petercooper on Sunday May 31, 2009 @11:32AM (#634742)
Life was just the first item on my list. I also said mathematics. There's plenty of precedent for programming languages to "mimic" mathematics due to being a branch of mathematics, after all. Having only one obvious way to do something is religious dogma unmatched by any similarly practical activity I can think of right now.
Re:Curing Python's Neglect by tvon on Saturday May 30, 2009 @03:31PM (#634022)
Seriously, that sounds like an absolutely horrible idea.
Re:Curing Python's Neglect by ii on Sunday May 31, 2009 @07:29AM (#634626)
You can monkey-patch your interactive interpreter BTW:

  >>> type(exit).__repr__ = lambda self: exit()
It will exit then the way you want :)

Nobody do it for the sake of overall consistency. Yet you are free to change it with the one line of code.