Editing text with an external editor in Python
Roy Smith
roy at panix.com
Mon Sep 1 13:06:21 EDT 2014
In article <54049ab7$0$29972$c3e8da3$5496439d at news.astraweb.com>,
Steven D'Aprano <steve+comp.lang.python at pearwood.info> wrote:
> import tempfile
>
> def edit(editor, content=''):
> f = tempfile.NamedTemporaryFile(mode='w+')
> [...]
> command = editor + " " + f.name
> status = os.system(command)
Hmmm. Didn't we just have a thread about passing external data to
shells?
$ mkdir '/tmp/;rm -rf;'
$ TMPDIR='/tmp/;rm -rf;' python
Python 2.7.3 (default, Sep 26 2013, 20:03:06)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tempfile
>>> f = tempfile.NamedTemporaryFile()
>>> f.name
'/tmp/;rm -rf;/tmpW8HFTr'
>>>
More information about the Python-list
mailing list