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.
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])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With