[Tutor] Pager in Python?

jfouhy@paradise.net.nz jfouhy at paradise.net.nz
Tue Jul 26 00:56:06 CEST 2005

> > > >Is there a command like more(1) or less(1) in python to display
> > > >the output of a command (e.g. dir()) one page at a time?

You could always write your own ...


def page(it, numLines=20):
   if isinstance(it, dict):
      it = it.iteritems()
   for i, x in enumerate(it):
      print x
      if (i+1) % numLines == 0:
         raw_input('Press <enter> to continue...')


More information about the Tutor mailing list