Last active
December 9, 2016 23:29
-
-
Save traverseda/13f82406a277e36a71ebac5310c20177 to your computer and use it in GitHub Desktop.
For https://github.com/jonathanslenders/ptpython/issues/155 . Edit datastructures in yaml using vim.
This file contains 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
from yaml import load, dump | |
try: | |
from yaml import CLoader as Loader, CDumper as Dumper | |
except ImportError: | |
from yaml import Loader, Dumper | |
import yaml, tempfile, subprocess, sys | |
def edit(data): | |
fd, temp_path = tempfile.mkstemp(prefix='punctual.') | |
with open(temp_path, "r+") as f: | |
f.write(yaml.safe_dump(data, default_flow_style=False, allow_unicode=True)) | |
f.truncate() | |
f.close() | |
while True: | |
with open(temp_path, "r+") as f: | |
subprocess.check_call('vim -c "set syntax=yaml" ' + temp_path, shell=True) | |
f.close | |
try: | |
data = yaml.load(open(temp_path,"r+").read()) | |
break | |
except Exception as E: | |
print(E) | |
input("Press Enter to continue...") | |
return data | |
edit({}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An example of some bad data for you
And some good data