02-24-2011, 03:38 AM | #1 |
Sigil developer
Posts: 1,275
Karma: 1101600
Join Date: Jan 2011
Location: UK
Device: Kindle PW, K4 NT, K3, Kobo Touch
|
JSONConfig has no delete method
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). |
02-24-2011, 06:21 AM | #2 |
Grand Sorcerer
Posts: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
JSONConfig inherits from XMLConfig, which does have a delete operation. Have you tried using "del json_object[key]"?
|
02-24-2011, 08:38 AM | #3 |
Sigil developer
Posts: 1,275
Karma: 1101600
Join Date: Jan 2011
Location: UK
Device: Kindle PW, K4 NT, K3, Kobo Touch
|
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).
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Method for seeing only the recent imports | peterloron | Calibre | 3 | 09-22-2010 04:02 PM |
"cannot import name JSONConfig" on launching calibre .42 | hakan42 | Calibre | 4 | 02-27-2010 03:37 AM |
Delete files in PC not equal to delete in Sony reader 505 | sheilalayoli | Sony Reader | 5 | 07-12-2009 03:13 PM |
Library management - your method? | thfc2008 | Sony Reader | 1 | 10-28-2008 10:24 AM |
alternate login method? | curtw | Feedback | 9 | 04-23-2008 11:05 PM |