Apologies for non-idiomatic Python; corrections on that welcome, but that's not my primary issue.
I am using plistlib to update keys in the the Info.plist file inside an application bundle. As far as I know, from the Python perspective, an application bundle is just a directory named "something.app". I'm having an issue, though, where calling plistlib.load(fp) followed by updating keys and then plistlib.dump(plist, fp) is appending the entire plist file's XML contents on the existing file, so that I end up with a file that has two entire XML trees inside it.
This is the code:
with open(plistPath, 'r+b') as fp:
plistRoot = plistlib.load(fp)
plistRoot["CFBundleIdentifier"] = newBundleId
plistlib.dump(plistRoot, fp)
I suppose I can always close the file context, blow away the file, and then open a new file with the same name and write to that, but it doesn't seem like that should be necessary.
Resolved by re-opening the file with a second with-as statement for writing.