Home Download Buy Blog Forum Support

Retrieve Key Bindings

Re: Retrieve Key Bindings

Postby svenax on Mon Apr 16, 2012 11:22 am

bizoo wrote:
svenax wrote:However, the Python json parser does not allow for comments, which are used in most default files. To handle that, you need a custom decoder object.

I use this code:
Code: Select all
RE_COMMENTS = re.compile('((//.*?$)|(/\*.*\*/))', re.M | re.S)
with open(keybindingfile) as f:
   content = f.read()
keybindings = json.loads(RE_COMMENTS.sub('', content))

Ah yes, that should work. As long as you dont have text that looks like comments inside strings in the json file that is ...
svenax
 
Posts: 155
Joined: Tue Dec 20, 2011 12:47 pm

Re: Retrieve Key Bindings

Postby bizoo on Mon Apr 16, 2012 12:30 pm

svenax wrote:Ah yes, that should work. As long as you dont have text that looks like comments inside strings in the json file that is ...

You're right, it's not fool proof.

This is probably a better solution (didn't try it):
https://github.com/getify/JSON.minify/blob/master/minify_json.py
bizoo
 
Posts: 889
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: Retrieve Key Bindings

Postby ostinelli on Tue Apr 17, 2012 2:24 am

thank you!

will use this as a starting point and will post back if i find better solutions!

r.
ostinelli
 
Posts: 15
Joined: Thu Apr 12, 2012 4:50 am

Previous

Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 11 guests