views:

165

answers:

3

Is there some python module or commands that would allow me to make my python program enter a CLI text editor, populate the editor with some text, and when it exits, get out the text into some variable?

At the moment I have users enter stuff in using raw_input(), but I would like something a bit more powerful than that, and have it displayed on the CLI.

A: 

If you don't need windows support you can use the readline module to get basic command line editing like at the shell prompt.

sth
+2  A: 

You could have a look at urwid, a curses-based, full-fledged UI toolkit for python. It allows you to define very sophisticated interfaces and it includes different edit box types for different types of text.

PhilS
Thanks, just what I needed!
Andrew
+4  A: 

Well, you can launch the user's $EDITOR with subprocess, editing a temporary file:

import tempfile
import subprocess
import os

t = tempfile.NamedTemporaryFile(delete=False)
try:
    editor = os.environ['EDITOR']
except KeyError:
    editor = 'nano'
subprocess.call([editor, t.name])
nosklo