gpt4 book ai didi

python - 使用 Python 读取二进制 Plist 文件

转载 作者:太空宇宙 更新时间:2023-11-03 12:34:38 28 4
gpt4 key购买 nike

我目前正在使用 PliSTLib 模块来读取 Plist 文件,但是当涉及到二进制 Plist 文件时,我目前遇到了一个问题。

我想将数据读入一个字符串,以便稍后进行分析/打印等。我想知道他们是否在不使用 plutil 函数并将二进制文件转换为 XML 的情况下读取二进制 Plist 文件?

感谢您的帮助和提前时间。

最佳答案

虽然您没有指定 plutil,但使用它的可行解决方案可能对其他人有用,因为它已预装在 Mac 上:

import json
from subprocess import Popen, PIPE

def plist_to_dictionary(filename):
"Pipe the binary plist through plutil and parse the JSON output"
with open(filename, "rb") as f:
content = f.read()
args = ["plutil", "-convert", "json", "-o", "-", "--", "-"]
p = Popen(args, stdin=PIPE, stdout=PIPE)
out, err = p.communicate(content)
return json.loads(out)

print plist_to_dictionary(path_to_plist_file)

关于python - 使用 Python 读取二进制 Plist 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8856032/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com