[IPython-user] displaying output one page at a time

ephesian send2philip@gmail....
Tue Jul 14 15:31:51 CDT 2009


Hi,
I use ipython a lot for analysing log files.  It is excellent for this kind
of work, but there is some paging functionality which I would like and which
I cannot find out how to do.  I have 4 questions below:

Example 1:  page lines for a log file
If the log file is small (e.g. under 1Gbyte) I can get away with
f = open(filename)
lines = f.readlines()
page lines

There are 2 disadvantages:
1)  If the log file is really large, I cannot do 'f.readlines()' as I do not
have enough memory
2) The output is not so nice e.g. newline is displayed as '\n' and there is
a comma between each line

QUESTION1: Is there a better way to do this ?


Example 2: page matching lines in a log file
Say I want to filter lines containin ERROR:
f = open(filename)
for line in f:
  if re.compile('ERROR').search():
    print line
But here the lines are displayed all in one go whereas I would like to
display one page at a time

QUESTION2:  is there a way to page the output


For the moment I use readline() as a workaround e.g.
f = open(filename)
n =0
for line in f:
  if re.compile('ERROR').search():
    print line
    n = n+1
    if n>NUM_ROWS:
      n = 0
      temp = os.sys.stdin.readline()

The disadvantage of this is twofold:
1) How do I guess the value of NUM_ROWS ?  It should be the number of lines
that my console can display
2) readline() requires you to hit return, where as it seems more natural to
hit spacebar e.g. like the 'more' command

QUESTION3: Is there some python module which can determine NUM_ROWS (the
number of lines that my ipython session can display on the console)

or

QUESTION4: Should I be looking into the curses module to try and implement
the unix 'more' command or can ipython give me something like this already ?


Sorry for the long post, I've been trying to figure this out for ages with
no success, any comments are appreciated !


-- 
View this message in context: http://www.nabble.com/displaying-output-one-page-at-a-time-tp24428346p24428346.html
Sent from the IPython - User mailing list archive at Nabble.com.



More information about the IPython-user mailing list