calling external programs

Gerhard Häring gh_pythonlist at gmx.de
Fri Dec 21 05:51:40 CET 2001


Le 21/12/01 à 03:10, bougle gluce écrivit:
> I was wanting to write a python program for linux that
> can call upon external programs. for instance the newsreader
> that I use is able to call my favorite text editor to edit
> this post, when I quit and save the text it saves it to a
> specific file then posts the text.
> 
> I think I understand how I might use system() to call upon
> another program. what I don't understand is how is it possible
> to take the user back to the calling program. for
> instance how do I end up back in my newsreader after I'm finished
> editing this post? and how did the editor know where to save 
> the file?

The newsreader will most likely do something like this:

import os
editor = "vim"
tempfile = os.tmpnam()

# Invoke editor
os.system(" ".join(editor, tempfile))

# Read back the text in order to post it
text = open(tempfile).read()

# Then delete the temporary file, ...

Gerhard
-- 
mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
web:    http://www.cs.fhm.edu/~ifw00065/    OpenPGP public key id 86AB43C0
public key fingerprint: DEC1 1D02 5743 1159 CD20  A4B6 7B22 6575 86AB 43C0
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))




More information about the Python-list mailing list