Last active
January 2, 2016 11:39
-
-
Save daGrevis/8297886 to your computer and use it in GitHub Desktop.
Edit text with editor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import subprocess | |
| import tempfile | |
| def edit_text_with_editor(text=""): | |
| _, location_for_temp_file = tempfile.mkstemp() | |
| with open(location_for_temp_file, "r+") as temp_file: | |
| temp_file.write(text) | |
| temp_file.flush() | |
| temp_file.seek(0) | |
| subprocess.call([os.environ['EDITOR'], location_for_temp_file]) | |
| edited_text = temp_file.read() | |
| os.remove(location_for_temp_file) | |
| return edited_text | |
| print(edit_text_with_editor("Hello, __!")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment