Idiom for shelling out to $EDITOR/$PAGER?

Cameron Simpson cs at zip.com.au
Fri Dec 23 14:47:53 EST 2011


On 23Dec2011 02:21, Devin Jeanpierre <jeanpierreda at gmail.com> wrote:
| > Anyway, look it up; it has an autodelete mode etc.
| 
| The autodelete isn't useful in this context. The file needs to be
| closed and then reopened again; with the autodelete option, the
| closing would delete the file, preventing it from being opened by the
| text editor or reopened to check contents.
| 
| (As far as I know, the race condition inherent in this is unavoidable.
| At least on windows, but I couldn't figure out any other way on Linux
| either.)

You can fire off the editor from inside the with statement.
Write contents, flush, edit, open T.name for read, read, close, exit
with statement.

Windows may hate you for this with its locking behaviour for open files,
but it will work for UNIX.

Cheers,
-- 
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

The elliptical cam has gradually slid up the beam shaft and caught on the
flange rebate dislodging the gripley, with disastrous results.
        - Death, 'Reaper Man' (Pratchett)



More information about the Python-list mailing list