Opened 19 months ago

Closed 18 months ago

Last modified 18 months ago

#326 closed defect (fixed)

python interactive help does not do CR/NL line endings.

Reported by: Steven Levine Owned by:
Priority: Feedback Pending Milestone:
Component: python Version:
Severity: low Keywords:


The python interactive mode help facility do not generate CR/NL line endings.

To reproduce, start with

python -i

From the python command line, enter


to request base64 module help.

The output will be paged, but with NL line endings rather than CR/NL line endings.

Change History (5)

comment:1 Changed 19 months ago by Silvan Scherrer

Priority: minorFeedback Pending

please try the following:
in file /@unixroot/usr/lib/python2.7/ change to the following:

def getpager():
    """Decide what method to use for paging through text."""
    if type(sys.stdout) is not types.FileType:
        return plainpager
    if not sys.stdin.isatty() or not sys.stdout.isatty():
        return plainpager
    if 'PAGER' in os.environ:
        if sys.platform == 'win32': # pipes completely broken in Windows
            return lambda text: tempfilepager(plain(text), os.environ['PAGER'])
        elif os.environ.get('TERM') in ('dumb', 'emacs'):
            return lambda text: pipepager(plain(text), os.environ['PAGER'])
            return lambda text: pipepager(text, os.environ['PAGER'])
    if os.environ.get('TERM') in ('dumb', 'emacs'):
        return plainpager
    if hasattr(os, 'system') and os.system('(less) 2>/dev/null') == 0:
        return lambda text: pipepager(text, 'less')
    if sys.platform == 'win32' or sys.platform.startswith('os2'):
        return lambda text: tempfilepager(plain(text), 'more <')

testing for less first and when not found it uses old ugly more. When you have less installed (which is a must anyway I'd say) then it should show a nice help page. If this works for you as well, I will make that the default.

Last edited 19 months ago by Silvan Scherrer (previous) (diff)

comment:2 Changed 19 months ago by Steven Levine

This is better.

I recommend changing

if hasattr(os, 'system') and os.system('(less) 2>/dev/null') == 0:


if hasattr(os, 'system') and os.system('less 2>nul') == 0:

It appears that os.system runs the command though the platform shell (aka cmd.exe or 4os2) rather than sh.exe.

If less.exe is not available, this results in


SYS0003: The system cannot find the path specified. "D:\dev\null"
Unknown command "less"

With my mod the SYS0003 goes away.

The more fallback can be improved. Changing to open call in tempfilepager from:

file = open(filename, 'w')


file = open(filename, 'wt')

seems to provide the results we want.

comment:3 Changed 18 months ago by Silvan Scherrer

I will consider this in the next python drop. When this happens is unknown atm.

comment:4 Changed 18 months ago by Silvan Scherrer

Resolution: fixed
Status: newclosed

this sys0003 is only there, if EXMSHELL is not set to sh. as our standard rpm set this value right, I did not change the sys003 workaround. the rest is done in r1551

comment:5 Changed 18 months ago by Steven Levine

I can confirm that help() now works as expected with the latest python rpm.

Note: See TracTickets for help on using tickets.