print in the interactive interpreter? plus shell API idea

hi! I am sure that Python interactive interpreter is a good tool. Before it were simple to print something with print. Now extra ( and ) are needed and also extra caution. Is it possible to have some simplified "print" in the interactive interpreter? IMHO, Basic's "?" is quite a good candidate. Maybe, it should not even be Python syntax but Python interactive shell feature. cf:
print(functools.wraps.__doc__)
and
? functools.wraps.__doc__
Also, some discussions about http://bugs.python.org/issue449227 (can't recall where they were, maybe private) indicate that maybe some kind of Python shell API could be interesting to facilitate Python interpreter's interaction with shells and provide better, more dynamic, experience to the shells' users (e.g. readline-like features, inline helps and hints, etc). With the API it will be easier for "vendors" to come up with CLUI/GUI/whatever shells. Shells will be thus decoupled from the interpreter itself. (WSGI is pretty similar in intention to abstract web service interaction, maybe the one I suggest may be called Rich Interpreter Shell Gateway Interface (RISGI) or something like that). The idea is quite raw, maybe not even pre-PEPable yet, because I am not really shell developer. It also differs from the way Python gets programmatically embed into something because the interface is really meant ot be like Python interpreter's "telnet" or "X", for humans. There could be addons to the shell protocol use (debugger or profiler subshells, datastructure/class/module browser subshell/subprotocol, help subshells). Special case shells (using same protocol) may be used, eg, for mobile phone Python. To put these topics in two: "standard" Python shell may provide keystroke shortcuts for some useful cases (like, today's shell is having underscore to mean most recently calculated expression value). So, "?" will not be part of the syntax but a shell's shortcut. I think that such shell protocol is quite unique for the programming languages and may be real breakthrough in interactive shell field and/or even whole CLUI. -Roman

On 05/07/2008, at 12:45, Roman Susi wrote:
in ipython you have: In [1]: functools.wraps? that will print the docstring and if you do ?? it will print the source code (or at least try to). Maybe one idea would be to list all different python interactive interpreters out there and try to come up with a pep describing improvements to the current python interpreter. Maybe list everything that could be done without readline (or any other similar library) and what depend on complex line editing facilities so there could become a option to the interpreter. -- Leonardo Santagada

Roman Susi wrote:
I am sure that Python interactive interpreter is a good tool.
Before it were simple to print something with print.
It always was and is easier to leave print off and just type the expression ;-)
Is it possible to have some simplified "print" in the interactive interpreter?
We already and always have had such: just type the expression

Terry Reedy wrote:
It gives you repr and its not always useful, e.g.
Well, my point which was completely ignored (maybe due to too lengthy explanation) is that the shell could be smarter beyond readline and that shell to interpreter protocol may be a well-defined API, specifying "main course" (Python commands) as well introspection features. Regards, Roman

On Sun, Jul 6, 2008 at 12:02 AM, Roman Susi <rnd@onego.ru> wrote:
I hear you, and I reject the feature request. This is a good area for 3rd party development -- e.g. ipython is currently the market leader. However, for the built-in interactive command line, I want there to be as little as possible difference with the language as accepted in modules. Any time you have a shortcut that works in interactive mode, somebody just learning the language is going to try it in a module and be very confused that it doesn't work. Clearly line editing operations are exempt from this argumentation, but I strongly dislike adding shortcuts like '?' for this reason. -- --Guido van Rossum (home page: http://www.python.org/~guido/)

Roman Susi wrote:
Before it were simple to print something with print. Now extra ( and ) are needed and also extra caution.
How often does one really need to use print in the interactive shell, given than you can just type an expression and get the repr of the result? -- Greg

On Sun, Jul 06, 2008, Greg Ewing wrote:
Actually, I use it frequently because typing "print EXPR" is easier than "str(EXPR)", and often enough the difference between str() and repr() is useful (especially in doctests). I guess when I upgrade to 3.0, I'm likely to switch to str() instead of print. -- Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha

On Sun, Jul 06, 2008 at 12:22:17PM +1200, Greg Ewing wrote:
It is is not always repr(): $ python Python 2.5 (release25-maint, Dec 9 2006, 14:35:53) [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-20)] on linux2 Type "help", "copyright", "credits" or "license" for more information.
Note the difference. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd@phd.pp.ru Programmers don't die, they just GOSUB without RETURN.

Oleg Broytmann wrote:
Python 2.5.2 (r252:60911, Apr 21 2008, 11:12:42) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. Readline loaded. History loaded.
Note the difference.
Can't see any difference in the latter example (matter of encodings, I guess), however, None is treated specially, it is true. At any rate, repr or not, its more typing to get the "nicer" result. My point is that the shell could be more sophisticated.
Oleg.
-Roman

On 05/07/2008, at 12:45, Roman Susi wrote:
in ipython you have: In [1]: functools.wraps? that will print the docstring and if you do ?? it will print the source code (or at least try to). Maybe one idea would be to list all different python interactive interpreters out there and try to come up with a pep describing improvements to the current python interpreter. Maybe list everything that could be done without readline (or any other similar library) and what depend on complex line editing facilities so there could become a option to the interpreter. -- Leonardo Santagada

Roman Susi wrote:
I am sure that Python interactive interpreter is a good tool.
Before it were simple to print something with print.
It always was and is easier to leave print off and just type the expression ;-)
Is it possible to have some simplified "print" in the interactive interpreter?
We already and always have had such: just type the expression

Terry Reedy wrote:
It gives you repr and its not always useful, e.g.
Well, my point which was completely ignored (maybe due to too lengthy explanation) is that the shell could be smarter beyond readline and that shell to interpreter protocol may be a well-defined API, specifying "main course" (Python commands) as well introspection features. Regards, Roman

On Sun, Jul 6, 2008 at 12:02 AM, Roman Susi <rnd@onego.ru> wrote:
I hear you, and I reject the feature request. This is a good area for 3rd party development -- e.g. ipython is currently the market leader. However, for the built-in interactive command line, I want there to be as little as possible difference with the language as accepted in modules. Any time you have a shortcut that works in interactive mode, somebody just learning the language is going to try it in a module and be very confused that it doesn't work. Clearly line editing operations are exempt from this argumentation, but I strongly dislike adding shortcuts like '?' for this reason. -- --Guido van Rossum (home page: http://www.python.org/~guido/)

Roman Susi wrote:
Before it were simple to print something with print. Now extra ( and ) are needed and also extra caution.
How often does one really need to use print in the interactive shell, given than you can just type an expression and get the repr of the result? -- Greg

On Sun, Jul 06, 2008, Greg Ewing wrote:
Actually, I use it frequently because typing "print EXPR" is easier than "str(EXPR)", and often enough the difference between str() and repr() is useful (especially in doctests). I guess when I upgrade to 3.0, I'm likely to switch to str() instead of print. -- Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha

On Sun, Jul 06, 2008 at 12:22:17PM +1200, Greg Ewing wrote:
It is is not always repr(): $ python Python 2.5 (release25-maint, Dec 9 2006, 14:35:53) [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-20)] on linux2 Type "help", "copyright", "credits" or "license" for more information.
Note the difference. Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd@phd.pp.ru Programmers don't die, they just GOSUB without RETURN.

Oleg Broytmann wrote:
Python 2.5.2 (r252:60911, Apr 21 2008, 11:12:42) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. Readline loaded. History loaded.
Note the difference.
Can't see any difference in the latter example (matter of encodings, I guess), however, None is treated specially, it is true. At any rate, repr or not, its more typing to get the "nicer" result. My point is that the shell could be more sophisticated.
Oleg.
-Roman
participants (7)
-
Aahz
-
Greg Ewing
-
Guido van Rossum
-
Leonardo Santagada
-
Oleg Broytmann
-
Roman Susi
-
Terry Reedy