How to make Python script flow like git commit?
For example if I write
git commit -m 'Commit message'
I create commit with this message. And if I write just
git commit
git suggest me to enter commit-message in text editor such VIM.
How to make Python script flow like git commit?
For example if I write
git commit -m 'Commit message'
I create commit with this message. And if I write just
git commit
git suggest me to enter commit-message in text editor such VIM.
Git's commit
command, when not given a -m
flag, calls your preferred editor with a temporary file, waits for the editor to exit, then reads out the file.
In Python, you would use os.system
or the more modern subprocess
library. Both will wait for the subprocess to end.
import subprocess, tempfile
tmpfile = tempfile.NamedTemporaryFile()
subprocess.call(["vim", tmpfile.name])
print("You wrote", tmpfile.read())
tmpfile.close()
(Of course, this example assumes that your preferred editor is Vim.)