More

Peter Hansen peter at engcorp.com
Thu Apr 17 19:51:46 CEST 2003


kpop wrote:
> 
> I usualy print strings the normal way
> print x, but if the string is too big it will
> go by the screen too fast and i wont be
> able to see anything. I notice the python
> internel help system hasa thing like the
> unix prgram more, where you press enter
> to go down. How can i use that in my own
> programs? Is there a function or a module.
> I am using windows so i dont have more.

Although this one is non-obvious, you can learn a lot by trying
to check the source.  I found how it works by doing this:

>>> type(help)
<type 'instance'>
>>> help.__class__
<class site._Helper at 0x00794990>
>>> help.__module__
'site'

Then I looked at site.py in the standard library, and found
that it uses pydoc for the help feature.

Looking at the source in pydoc.py, I could see a variety of 
"pagers" that are related to this function.

After a false start trying to do this:

 pydoc.ttypager(longstring)

which did nothing effective, I noticed getpager() just above it.

>>> pydoc.getpager()(longstring) 
long strinxlong strinxlong strinxlong strinxlong strinxlong strinxlong strinxlon
g strinxlong strinxlong strinxlong strinxlong strinxlong strinxlong strinxlong s
trinxlong strinxlong strinxlong strinxlong strinxlong strinxlong strinxlong stri
nxlong strinxlong strinxlong strinxlong strinxlong strinxlong strinxlong strinxl
ong strinxlong strinxlong strinxlong strinxlong strinxlong strinxlong strinxlong
 strinxlong strinxlong strinxlong strinxlong strinxlong strinxlong strinxlong st
-- More --


Hmm... seems to work okay.  I'm sure you can learn more by looking
at the internals of pydoc a little more... or maybe this stuff is
even documented if you check the docs!  

-Peter




More information about the Python-list mailing list