-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
Make help() beginner helpful when no PAGER or LESS variable #65824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
From the #python IRC channel:
Why does help() enter a more-mode for even short help? Why doesn't ENTER get you out of it? Why doesn't the prompt have a suggestion of how to get out of it? Why does it clear the screen when you are done with it, removing all the help from the screen? It seems very geeky, and not that help-ful. I'm sure there's something we can do to make this a little easier for newbs. |
ENTER scrolls. Type a number N to scroll by N lines.
The option -X (no-init) should stop
I guess no one thought to add that when You can customize the pager using the PAGER environment variable, as used by other commands such as $ PAGER='less -eX' python3 -c 'help(help)'
Help on _Helper in module site object:
class _Helper(builtins.object)
[...] You can also set pydoc.pager directly, which is what IDLE does: >>> pydoc.pager = pydoc.plainpager
>>> help(help)
Help on _Helper in module site object:
[...] plainpager is the default if the TERM environment variable is dumb or emacs, or if sys.stdout isn't a tty. Otheriwse if the system has neither On Windows, text is written to a temp file using tempfilepager. Other platforms pipe the text using pipepager. This should also work for Windows in Python 3, which implements os.popen with subprocess.Popen. Here's a test using GnuWin32 head.exe and tr.exe: >>> cmd = 'head -n3 | tr [:lower:] [:upper:]'
>>> pydoc.pager = lambda t: pydoc.pipepager(t, cmd)
>>> help(help)
HELP ON _HELPER IN MODULE _SITEBUILTINS OBJECT:
CLASS _HELPER(BUILTINS.OBJECT) |
Thanks, this is a very complete explanation of the machinery behind the scenes. I think we would do beginners a service if we made the behavior a bit less obscure. Are there ways that we could (for example) have the prompt say "END (q to quit)" instead of just "END"? |
Add following command to your profile file (~/.profile, ~/bashrc, or ~/.bash_aliases):
And please don't break help(). It works as expected (to Unix users) and is enough configurable. |
Serhiy, thanks for the configuration tip. But you seem to be missing my point, which is that beginners need the default to be a little more friendly. I don't want to make it bad for experienced users, of course. I doubt Unix users will be confused by seeing "END (q to quit)" as a prompt. |
You can use '-P?e(END) .(q to quit)' to add (END) just on the last line. Or show the line count instead:
|
There is also an option to make less quit if enter is pressed on the last line (-e/--quit-at-eof). These more beginner friendly options could be provided by pydoc if there is no existing PAGER or LESS environment variable. |
I recently opened Python in a Mac Terminal (bash) window, tried help(ob), and being a beginner in this situation, had the same terrible frustrating experience. I am leaving this open to implement David Murray's suggestion and changed the title accordingly. On Windows, in Command Prompt and Power Shell, a prompt appears when help output is done and the text remains. This is the same as when one enters any other Python statement that produces output. (The only difference is the intermediate paging.) I think that this standard Python behavior, or something close, should be the default help behavior on all systems. (It is on IDLE.) |
I would request us to think about a couple more options while this is under consideration... Do we want to also add the flags -X and -F to the less options? The -X flag gets less to show its output inline, instead of a separate screen. The advantage here is that users can now see the last viewed help page right above the prompt even after quitting help. It helps immensely to be able to see the help and write statements based on the help. The minor downside is that the last statements typed on the python prompt have now scrolled farther up. The -F (or --quit-if-one-screen) flag exits helps automatically if the help contents fit less than one screen-full. This is only useful when used in conjunction with the -X flag. If we do decide to use the -X flag, then this flag becomes an obvious choice. If we do choose to use these flags, the less command now becomes
|
Output the line number, the percent and help about how to get help or quit the pager.
Output the line number, the percent and help about how to get help or quit the pager. Inspired by the GNU man.
Output the line number, the percent and help about how to get help or quit the pager. Inspired by the GNU man.
#116050 is an alternative solution, heavily inspired by the GNU implementation of
|
Output the line number, the percentage and the help about how to get help or quit the pager. Inspired by the GNU man.
#116183 adds "Help on XXX" to the Now the prompt looks like:
or
|
Output the line number, the percentage and the help about how to get help or quit the pager. Inspired by the GNU man.
Output the line number, the percentage and the help about how to get help or quit the pager. Inspired by the GNU man.
Output the line number, the percentage and the help about how to get help or quit the pager. Inspired by the GNU man.
Triage: the linked PRs are merged, can this be closed? |
I only made changes that I thought were worth making. But there were other proposals. I do not know whether this is enough for the OP. |
@nedbat Would you like to do more for this issue (if so, what?) or shall we close it? |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
The text was updated successfully, but these errors were encountered: