python - 在 python 中编辑 plist

标签 python linux unix plist

我有一个如下的 plist 文件,我想从 python 脚本中编辑它。我有一个安装 python 脚本,我想在安装完成后将“InitSetupComplete”值更改为字符串“YES”。我已经尝试过在堆栈溢出中找到的一些 python 片段,但 plist 仍未编辑。我很可能在我的代码中犯了一个错误。关于出了什么问题有什么想法吗?我是否需要 chmod plist 以便脚本可以编辑它?

boot_info.plist:

<?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>InitSetupComplete</key>
    <string>NO</string>
</dict>
</plist>

设置.py

import sys
import plistlib

//Do Setup Here...

//Change Setup Value to YES
pl = plistlib.readPlist("boot_info.plist")
del pl["InitSetupComplete"]
pl["InitSetupComplete"] = { 'InitSetupComplete': 'YES' }
sys.exit()

最佳答案

我认为您只需要在完成编辑后调用 writePlist 即可。 Here是一篇关于使用此模块的好文章。

关于python - 在 python 中编辑 plist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23890152/

相关文章:

python - 如何使用带有 GStreamer 后端的 OpenCV Python 创建 x264 RTSP 服务器

python - Python 中的一切都像 Ruby 一样是对象吗?

python,在中位数附近找到置信区间

c - 如何从输入文件在 C 中创建动态字符串数组

linux - 使用 bash 脚本从文件中读取元素

python - 在 Python 中构建二维数组

linux - SO_REUSEPORT 套接字服务器

linux - 如何使屏幕 session 使用与原始终端相同的设置

linux - linux下如何查找字符串

c - 我的 C 代码中几乎没有错误吗?