With plistlib I can serialize a dictionary / list structure into a plist. This works ok and I can also read it back with the same library.
The problem is that dictionaries are of type “_internalDict” and I don’t seem to be able to change them. For exampl, for example:
d = plistlib.readPlist('someplist.plist')
v = d['value'] # v is an _internalDict
v['val'] = 'new val' # works
del v # doesn't work
v = {'someotherkey': 'someothervalue'} # doesn't work either
The plist doesn’t seem to change. Help?
You’ll need to delete the key from the
ddict:By setting
v = d['value']you are only creating a new variable that points to the same value asd['value'], but deletingvwill not remove the dict from the parent structure.To replace the dict altogether, you again need to manipulate the parent dict:
If you execute
v = { ... }what you are doing is assigning a reference to a newdictvalue to the variablev, replacing the reference to thed['value']dict; you are not manipulating the original value in theddict.plistlib._InternalDictis just a subclass ofdictthat gives warnings for attribute access, which is now deprecated; otherwise it acts just like a regulardicttype.