Python:更新plist文件的值

时间:2016-05-17 09:17:51

标签: python-3.x parsing plist

可以自动更新plist文件中特定字段的脚本。我想更新plist中的具体值。

我想改变“颜色”值。在python 3.5中怎么可能?

示例:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"   
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
 <key>AlarmFilter</key>
<true/>
 <key>AlarmsDisabled</key>
<false/>
<key>AttachmentFilter</key>
<true/>
<key>AutoRefresh</key>
<true/>
<key>Checked</key>
<integer>1</integer>
<key>Color</key>
<string>#808000FF</string>
</dict>
</plist>
我写了这段代码:

import plistlib
answer = plistlib.readPlist('plist_path')

ans = dict.values(answer)
ans1 = dict.keys(answer)


que = input('Enter Element Name:- \n')
try:
p  = answer[que] = "ravi"
plistlib.writePlist(p, answer)
except:
print("Failure")

0 个答案:

没有答案