Mobileread
JSONConfig has no delete method
#1  meme 02-24-2011, 03:38 AM
JSONConfig in utils/config.py allows set/get but not delete of a specific key. Is it possible to delete a key from a plugin's json file?

Normally I don't need this, but I'm renaming a key and the only way I found to 'remove' the old key is to set the old key value to Null.

This is sufficient, although it leaves old/unused data in the file, and it means an extra test is needed since the key exists but the data is Null (since get(store_name, DEFAULTS) will not set the key to DEFAULTS if the key exists but is a dict with Null).
Reply 

#2  chaley 02-24-2011, 06:21 AM
JSONConfig inherits from XMLConfig, which does have a delete operation. Have you tried using "del json_object[key]"?
Reply 

#3  meme 02-24-2011, 08:38 AM
That was it, thanks. I've used the del statement elsewhere, and noticed that XMLConfig inherits from dict, but didn't connect using del on it would work like del for a dict. The del statement is a bit odd anyway since most everything else is called like a function - I was looking for a del() method and all I could see was __delitem__ (which given the __ I believe is an internal method).
Reply 

Today's Posts | Search this Thread | Login | Register