473,320 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

putting text through pager

Hi,

I'm trying to print some variable through a pager (i.e. 'less') on a
linux system. My attempt was this:
====== snip here ======
import subprocess

def put_through_pager(displaystring):
less_pipe = subprocess.Popen(\
'less', shell=True, \
stdin=subprocess.PIPE).stdin
less_pipe.write(displaystring)
less_pipe.close()

def main():
put_through_pager(longstring)
longstring = """
Lorem ipsum dolor sit amet,...
http://www.lipsum.com/
"""

main()

====== snip here ======

That doesn't work however: first of all, it only flashes the text for a
fraction of a second, and secondly, after I run the program my terminal
is broken, not echoing whatever I type back to me.

Any suggestions for putting text through a pager from Python? This is
strictly on a linux system, of course.

Thanks,
Michael
Mar 20 '08 #1
1 1382
Michael Goerz wrote, on 03/20/2008 04:43 PM:
Hi,

I'm trying to print some variable through a pager (i.e. 'less') on a
linux system. My attempt was this:
====== snip here ======
import subprocess

def put_through_pager(displaystring):
less_pipe = subprocess.Popen(\
'less', shell=True, \
stdin=subprocess.PIPE).stdin
less_pipe.write(displaystring)
less_pipe.close()

def main():
put_through_pager(longstring)
longstring = """
Lorem ipsum dolor sit amet,...
http://www.lipsum.com/
"""

main()

====== snip here ======

That doesn't work however: first of all, it only flashes the text for a
fraction of a second, and secondly, after I run the program my terminal
is broken, not echoing whatever I type back to me.

Any suggestions for putting text through a pager from Python? This is
strictly on a linux system, of course.

Thanks,
Michael
Using a tempfile seems to be a good solution:

def put_through_pager(displaystring):
(temp_fd, tempname) = tempfile.mkstemp(".mail")
temp_fh = os.fdopen(temp_fd, "w")
temp_fh.write(displaystring)
temp_fh.close()
os.system("less %s" % tempname)
os.unlink(tempname)
Mar 20 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

36
by: Richard | last post by:
My employer currently pays me $1/hour when I carry a pager. I have to carry the pager every fourth week. The problem is that my employer insists that I be available when I'm carrying the pager. ...
13
by: Ennio-Sr | last post by:
Hi all! After a very long struggle I finally succeded in transferring my old *.dbf file and the relating *.dbt (alias memo fields) to a pg table. For the time being I put the memo field in a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.