paging in python shell

A

Alex K

Hello,

Does anyone know if the python shell supports paging or if I should
look into iPython? Thank you so much.

Alex
 
T

Tim Roberts

Alex K said:
Does anyone know if the python shell supports paging or if I should
look into iPython? Thank you so much.

"Paging" is an overloaded term. What do you mean, exactly? Do you mean
something like piping the output into "more"? The Python shell does that
for the "help" command, but maybe you could post a more precise example of
what you want.
 
J

John Machin

Hi Tim,

Yes I mean piping the output into "more" for example.

Why don't you "suck it and see"???

E.g.

C:\junk>copy con demomore.py
for i in range(100):
print 'line', i
^Z
1 file(s) copied.

C:\junk>python demomore.py | more
line 0
line 1
line 2
line 3
line 4
[snip]
line 50
line 51
line 52
line 53
line 54
line 55
line 56
-- More --
 
A

Alex K

Thanks John, but would it be possible to remain in the python interpreter?

Hi Tim,

Yes I mean piping the output into "more" for example.

Why don't you "suck it and see"???

E.g.

C:\junk>copy con demomore.py
for i in range(100):
print 'line', i
^Z
1 file(s) copied.

C:\junk>python demomore.py | more
line 0
line 1
line 2
line 3
line 4
[snip]
line 50
line 51
line 52
line 53
line 54
line 55
line 56
-- More --
 
B

Ben Finney

John Machin said:
C:\junk>python demomore.py | more

Your example uses the OS shell to invoke a pager on the output of the
Python process. The OP was asking about paging *within* the Python
shell.

To my knowledge there's nothing in the default Python shell that
enables what the OP is asking for. There are other Python shells, e.g.
Idle, ipython, or a Python window inside Emacs, that may be better
suited.
 
G

Gabriel Genellina

En Mon, 14 Jan 2008 21:05:38 -0200, Ben Finney
To my knowledge there's nothing in the default Python shell that
enables what the OP is asking for. There are other Python shells, e.g.
Idle, ipython, or a Python window inside Emacs, that may be better
suited.

Yes, there is. Thanks to Tim Roberts who menctioned that the builtin help
system implements paging internally, I looked at it. It's easy to use (but
maybe too late for the OP):

Let Python determine the best pager available:

import pydoc
pydoc.pager(text)

(it may pipe the text into an external program like less or more). Or
explicitely use the builtin pager:

import pydoc
pydoc.ttypager(text)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top