Request for comments: Search and replace script

Fernando Pérez fperez528 at yahoo.com
Fri Feb 22 15:14:09 EST 2002


VanL wrote:

> Sort of a poor man's 'more' for when this is run on a windows system.
> 

you can take this

#----------------------------------------------------------------------------
def page_dumb(strng,start=0,screen_lines=25):
    """Very dumb 'pager' in Python, for when nothing else works.

    Only moves forward, same interface as page(), except for pager_cmd and
    mode."""

    ncols = 80
    out_ln = strng.splitlines()[start:]
    out = []
    for ln in out_ln:
        if len(ln) <= ncols:
            out.append(ln)
        else:
            out.extend(chop(ln,ncols))
    screens = chop(out,screen_lines-1)
    #print '\nscreens is:',screens,os.linesep  # dbg
    if len(screens) == 1:
        print os.linesep.join(screens[0])
    else:
        for scr in screens[0:-1]:
            print os.linesep.join(scr)
            ans = raw_input('---Return to continue, q to quit--- ')
            if ans.lower().startswith('q'): return
        print os.linesep.join(screens[-1])


If you want its bigger brother, page() (multi-os, with solid fallbacks) go to 
http://www-hep.colorado.edu/~fperez/ipython/

page() and family are in the genutils.py module (plus lots of other useful 
stuff). It's LGPL, so feel free to use it.

cheers,

f.



More information about the Python-list mailing list