4 ms·
Isn't this due to some REPL-constraints or not wanting to break the way the language works? Maybe there's no way to evaluate the "exit" and "help" objects repla
by usui 5y ago
Isn't this due to some REPL-constraints or not wanting to break the way the language works? Maybe there's no way to evaluate the "exit" and "help" objects replaced by "exit()" and "help()", and that making exceptions would clutter the code. Not sure the reasoning behind it, but that's what it seems.
- lou1306 5y ago> not wanting to break the way the language works This is the reason. "help" and "exit" (as well as "quit") are perfectly cromulent variable names in Python. So the REPL does the best possible thing, i.e., try and evaluate the expression and shoot a message if it fails. Case in point: >>> help = "hi" >>> help "hi" >>> del help >>> help Type help() for interactive help, or help(object) for help about object.
- blt 5y agoWhy not: - check if a variable called "help" is in scope - if not, call help(). - otherwise, print its value.
- Brian_K_White 5y agoBecause then when there IS a variable, the help command you learned will not work. I think anyone crying and baffled about this is fundamentally not well suited to programming. This sort of logical problem should be intuitive. The seeming irrationality of the special case behavior is just something funny to make your mom laugh, not something that's actually illogical or inconsistent or stupid.
- lou1306 4y agoWhat if you have defined a "help()" function though? REPL should be as dumb as possible. That's a feature, not a bug.